如何在表单提交中使用PHP函数进行操作?
我正在使用此表单和函数来感知sms,我需要在表单操作中使用函数方面的帮助,我将如何进一步操作?我应该直接在表单的操作部分添加函数,还是使用任何ajax来调用函数 请告诉我处理这种情况的简单方法,这是处理过程的正确方法吗如何在表单提交中使用PHP函数进行操作?,php,forms,Php,Forms,我正在使用此表单和函数来感知sms,我需要在表单操作中使用函数方面的帮助,我将如何进一步操作?我应该直接在表单的操作部分添加函数,还是使用任何ajax来调用函数 请告诉我处理这种情况的简单方法,这是处理过程的正确方法吗 <?php function sendSMS($mobile,$message,$senderid){ $user = "APIKEY"; $url = 'http://login.smsgatewayhub.com/api/mt/SendS
<?php
function sendSMS($mobile,$message,$senderid){
$user = "APIKEY";
$url = 'http://login.smsgatewayhub.com/api/mt/SendSMS?APIKey='.$user.'&senderid='.$senderid.'&channel=INT&DCS=0&flashsms=0&number='.$mobile.'&text='.$message.'&route=16;';
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,2);
$data = curl_exec($ch);
print($data); /* result of API call*/
}
$senderid =$_POST['senderid'];
$message = rawurlencode($_POST['message']);
$mobile="0123456789";
sendSMS($mobile,$message);
?>
移动电话*
选择发件人ID*
选择发件人ID
福里托
KWKMNT
KWKVEG
输入消息*
您必须首先为按钮submit指定名称
<input type="submit" name="submit" class="btn btn-primary btn-sm" value="Send SMS">
然后调用表单提交上的函数
<?php
if(isset($_POST['submit'])){
$senderid =$_POST['senderid'];
$message = rawurlencode($_POST['message']);
$mobile = isset($_POST['mobilenumber']) ? $_POST['mobilenumber'] : '';
sendSMS($mobile,$message);
}
?>
您还需要在表单中添加一个操作URL,以便接收所有发布的数据
<form method='post' action='pathToController'>
首先需要检查值是否已设置,然后调用function@sairam达吉。您还需要在html表单元素的action属性中添加URL(该.php文件)。
<form method='post' action='pathToController'>
$senderid =$_POST['senderid'];
$message = rawurlencode($_POST['message']);
$mobile="0123456789";
sendSMS($mobile, $message, $senderid);//pass senderid as well