0

I've built a WordPress plugin, this plugin has a form in front-end using a shortcode I need the submit button to do two things, first to send the entries to the database which I did it successfully. The second thing is to build a URL from entries and run it

this is the form code:

<form name="frm" action="#" method="post" enctype="multipart/form-data">
        <tr>
            <td><?php echo __( 'Your Name', 'msf')?></td>
            <td><input type="text" name="nm"></td>
        </tr>
        <tr>
            <td><?php echo __('Mobile no' , 'msf' )?></td>
            <td><input pattern="\d*" maxlength="9" type="number" name="mob"></td>
        </tr>
        <tr>
            <td></td>
            <td><input class="button-primary" type="submit" value="<?php echo __('Send' , 'msf' )?>" name="ins" action=""></td>
           <!-- alert -->
            <div class="success_msg" style="display: none">Message
                Sent Successfully</div>

            <div class="error_msg" style="display: none">Message
                Not Sent, There is some error.</div>
        </tr>
    </form>

this is my function

function SMS_SEND($message,$numbers)
    {
    $text = urlencode($message);
    $to = $numbers;
    $user="";
    $pass="";
    $sender="";
    $ch = curl_init();
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; pt-BR; rv:1.9.2.18) Gecko/20110628 Ubuntu/10.04 (lucid) Firefox/3.6.18' );
curl_setopt( $ch, CURLOPT_URL, 'http://www.*****.com/sms/api/sendsms.php?username='.$user.'&password='.$pass.'&numbers='.$to.'&sender='.$sender.'&message='.$text );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$result = curl_exec ( $ch );
curl_close ( $ch );
    return nl2br($result); 
     }
3
  • You can't call a PHP function on a page, PHP happens on the server, so you'll need to make a new request to the server via AJAX. Take a look at creating a rest api endpoint to make the request to with register_rest_route
    – Tom J Nowell
    Sep 11, 2020 at 22:09
  • Also be careful, what you've asked for has no checks, so anybody could use this to send any message they want to any number as often as they want for free ( you'd be paying for it ), it's a great way to send spam to people, stalk victims, send abusive messages, and it'd all be under your account name paid foor by you. That's why the sms library has usernames and passwords, which all get bypassed by your SMS_SEND function
    – Tom J Nowell
    Sep 11, 2020 at 22:13
  • Thank toy Tom, i'm WordPress developer beginner, can you suggest search terms to learn more about handling form with AJAX in WordPress ? Sep 11, 2020 at 22:34

1 Answer 1

0
    <?php
        if(array_key_exists('button1', $_POST)) { 
            button1(); 
        } 
        function button1() { 
            echo "This is Button1 that is selected"; 
        } 
    ?> 

    <form method="post"> 
        <input type="submit" name="button1"
                class="button" value="Button1" /> 
        
    </form> 
</head> 

</html> 

you call button click function this type you need more refrance follow this link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.