繁体   English   中英

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

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

我有一个基本的帖子表单,可以将一些数据提交到 SMS 网关。 隐藏字段之一“消息”是我希望发送出去的消息文本。 我需要两个提交按钮用于两个不同的位置(case1 和 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>

您可以使用具有相同名称的按钮。 他们将根据单击的变量填充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>

与其拥有两个提交按钮,不如拥有一个,然后将两个消息字段作为文本,然后用户可以根据任何情况键入消息。 然后不要将表单直接提交到短信网关,而是将表单发送到服务器中的脚本以验证使用了哪种情况,然后使用 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);
?>

暂无
暂无

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

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