简体   繁体   English

一个表单,两个提交按钮,用于两个不同的隐藏值

[英]one form, two submit buttons for two different hidden values

I have a basic post form that submits some data to an SMS gateway.我有一个基本的帖子表单,可以将一些数据提交到 SMS 网关。 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.我需要两个提交按钮用于两个不同的位置(case1 和 case2)——每个按钮在“消息”值中传输不同的文本。 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.我只需要两个提交按钮——一个用于case1,一个用于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>

You could use buttons with the same name.您可以使用具有相同名称的按钮。 They will populate the message variable based on which one was clicked.他们将根据单击的变量填充message变量。

<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>

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.然后不要将表单直接提交到短信网关,而是将表单发送到服务器中的脚本以验证使用了哪种情况,然后使用 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 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);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM