Hi there, I have some code which works pretty fine with the variables filled in from a SMS gateway provider: <?php //set up variables $info = "1"; $test = "0"; $address = "www.xxx.com/sendsms.php"; $message = "Hello this is a test"; $message = urlencode($message); $from = " "; $uname = " "; $pword = " "; $selectednums = " "; //build url $data = "uname=" . $uname . "&pword=" . $pword . "&message=" . $message . "&from=" . $from . "&selectednums=" . $selectednums . "&info=" . $info . "&test=" . $test; //send messages $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://$address"); //curl_setopt($ch, CURLOPT_URL,"https://$address"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); output $result = curl_exec ($ch); curl_close ($ch); ?> PHP: I go to the page and the script sends the SMS - cool. How do I go about adding a form for the message and a submit button so that users can put in a custom message and the script does not execute straight away? I have tried adding something like: <form action="<? echo $PHP_SELF; ?>" method="post"> <label for="message" class="sb1">Message:</label><br /><br /> <textarea name="message" id="txtarea"><? echo $message; ?></textarea><br /><br /> <input type ="hidden" name="tried" value="yes" /> <input type="submit" id="btnsubmit" name="Submit" value="<? echo $tried ? 'continue' : 'send'; ?>"> </form> HTML: But its not working yet. I think this is an easy one, but not to a PHP noob like myself
When the user submits the form you now need to get the data from the form into your $message variable. This should do it: $message = $_REQUEST['message']; You'll likely need to do some validation of the message - like ensure it's not too long and all that - before you use it.
many thanks jnestor. I opted to use: $message = $_POST['message']; and it looks like its running fine, although I have got an error message from the script / provider when the page loads: Error=Message not sent. Please check your data - especially the numbers. Are they all in INTERNATIONAL format? Message: Any ideas how to get rid of this - it would be okay if it was just me using this as I could ignore it but I am thinking of my users.. The message box and submit now works though... Also how to validate - I guess as this is a SMS service I am limited to 160 characters - any clues as to how I should go about this? Thanks again Alffy