i trying make form people fill out requests service. must 1 of fields enter phone number. ensure phone number valid have set php send sms provided number using providers api.
the sms sends okay , sends php variable enclosed. (a random int between 9999 , 99999.) code sent every submit code changes function runs. problem receive text when enter in code has changed submitted form validate. have tried using button type in html cant figure our how run php using it. below first form fill out sends message.
<?php $confirmcode = rand(9999, 99999); //echo "<br/><br/><br/><br/><br/><br/>confirmation code:"."<br/><br/>$confirmcode<br/><br/><br/>"; if (isset($_post['submit'])){ // validation //check name non-blank if( 0=== preg_match("/\s+/", $_post['fname'])){ $errors['first_name'] = "please enter name."; } if (0=== preg_match("/^[\+0-9\-\(\)\s]{10,}+$/", $_post['phone'])){ $errors['phone'] = "please enter phone number"; } //check email has required symbols if (0=== preg_match("/.+@.+\..+/", $_post['email'])){ $errors ['email'] = "please enter valid email address."; } //end validation $errors = array(); $name = $_post['fname']; $address = $_post['address']; $phone = $_post['phone']; $email = $_post['email']; //sending confirmation sms code confirm phone number. // declare security credentials use $username = "############"; $password = "############"; // set attributes of message send $message = "hello " ."$name" ."your confirmation code is: " ."$confirmcode".". " ."please enter .". "on appraisal request form."; $type = "1-way"; $senderid = "sanctuaryre"; $to = $_post['phone']; // build url send message to. make sure // message text , sender id url encoded. can // use http or https $url = "http://api.directsms.com.au/s3/http/send_message?" . "username=" . $username . "&" . "password=" . $password . "&" . "message=" . urlencode($message) . "&" . "type=" . $type . "&" . "senderid=" . urlencode($senderid) . "&" . "to=" . $to; // send request $output = file($url); // response gateway going // this: // id: a4c5ad77ad6faf5aa55f66a // // in event of error, this: // err: invalid login credentials $result = explode(":", $output[0]); //end sms header("location: process.php"); } ?> and form pushed onto confirm code sent.
<html> <div class="wrapper2"> <form action="" method="post"> <input type="text" class="textfieldlong" placeholder="confirmation code" name="giventoken"> <input type="button" class="submit" value="verify phone number" name="submit2" id="submit2"> </form> </html> <style> .wrapper{ display:none; } </style> </div> <?php include "index.php"; //$token = $_post['giventoken']; //if (!strcmp($confirmcode,$token)){ // echo "match"; //} echo "$confirmcode"; ?> the random int generated right @ beginning. please help! thnx. :d
the random number being created every time.
you have database number each specific user , check when enter code. cant expect user text , confirm immediately. real way database it.
setup table userid , code, check when confirm sent code user.
Comments
Post a Comment