单击提交时调用Function

时间:2020-09-11 作者:Mohamed Mostafa

我已经构建了一个WordPress插件,这个插件在前端有一个使用快捷键的表单。我需要提交按钮来完成两件事,首先是将条目发送到我成功完成的数据库。第二件事是根据条目构建URL并运行它

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>
这是我的职责

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); 
     }

1 个回复
最合适的回答,由SO网友:bca tech 整理而成
    <?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