0
votes

I have a basic post form that submits some data to an SMS gateway. One of the hidden fields "message" is the text of the message that i wish to be sent out. I need two submit buttons for two different sitations (case1 and case2) - each one transmits a different text in the "message" value. I cant do anything server side as the data is sent to a third party gateway. Any advice?

current code is:

I just need two submit buttons - one for case1 and one for case2.

<form action="https://gatway.com/send.php" method="post">
<input name="key" type="hidden" value="APIKEYxxxxx" />
<input name="message" type="hidden" value="message to send in case 1" />
<input name="message" type="hidden" value="message to send in case 2" />
To: <input name="to" type="text" />
<input name="username" type="hidden" value="username" />
<input name="from" type="hidden" value="+44xxxxxxxxxx" />

<input type="submit" value="Submit" /></form>
2
if you can edit the form, then you can add a change in the form parameters using javascript onSubmit. edit form.action, for examplebars

2 Answers

2
votes

You could use buttons with the same name. They will populate the message variable based on which one was clicked.

<form action="https://gatway.com/send.php" method="post">
    <input name="key" type="hidden" value="APIKEYxxxxx" />
    To: <input name="to" type="text" />
    <input name="username" type="hidden" value="username" />
    <input name="from" type="hidden" value="+44xxxxxxxxxx" />
    <button type="submit" name="message" value="message to send in case 1">Submit 1</button>
    <button type="submit" name="message" value="message to send in case 2">Submit 2</button>
</form>
0
votes

How about instead of having two submit buttons, have one then have the two message fields as text then user can type the message based on whatever case. then instead of submitting the form directly to the sms gateway send the form to your script in your server to validate which case was used then send the post data to the sms gateway with CURL.

<form action="smschecker.php" method="post">
    <input name="key" type="hidden" value="APIKEYxxxxx" />
    <input name="message1" type="text" value="message to send in case 1" />
    <input name="message2" type="text" value="message to send in case 2" />
    To: <input name="to" type="text" />
    <input type="submit" value="Submit" />
</form>

smschecker.php

<?php
define('SMS_SERVICE_URL', 'https://gatway.com/send.php');
define('username', 'username_here');
define('password', 'password_here');
define('key', 'YOUR_KEY/SID_HERE');
define('from', "+44xxxxxxxxxx");

if (isset($_POST['message1']) && !empty($_POST['message1'])) {

    $message = $_POST['message1'];
}

if (isset($_POST['message2']) && empty($_POST['message2'])) {

    $message = $_POST['message2'];
}

$to   = $_POST['to'];
$from = $_POST['from'];


$sms = array(
    "to" => $to,
    "message" => $message,
    "from" => from
);



$post = array(
    'user' => username,
    'pass' => password,
    'key' => key,
    'sms' => $sms
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, SMS_SERVICE_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

curl_close($ch);
?>