[英]php populate listbox dynamically without submitting form
我會盡力解釋這一點。
我有一個接受多個字段的表單,最后,將所有字段通過電子郵件發送到特定的電子郵件地址。
例如,我有三個文本框,一個列表框和兩個提交按鈕。
其中兩個文本框是名字和電子郵件地址
第三個文本框用於填充列表框。 因此,如果我在第三個文本框中輸入NIKE,然后按第一個提交按鈕。 現在,耐克將出現在列表框中。
我希望能夠在列表框中填充所需的條目,然后按第二個“提交”按鈕發送所有信息(名字,電子郵件地址和列表框中的所有項目)。
問題是,按“提交”后,按第一個提交按鈕始終會觸發發送的電子郵件。
我現在一切正常。 第三個文本框將新數據提交到mysql中的表中,然后檢索所有數據並將其放在列表框中。
解決此問題的最佳方法是什么? 我能否停止Post變量的驗證,直到使用第二個Submit按鈕?
另外,我想避免使用Javascript,謝謝
確保兩個提交按鈕具有名稱。 IE: <input type="submit" name="command" value="Add">
和<input type="submit" name="command" value="Send">
。 然后,您可以使用PHP確定單擊了哪個PHP:
if($_REQUEST['command'] == 'Add')
{
// Code to add the item to the list box here
}
elseif($_REQUEST['command'] == 'Send')
{
// Code to send the email here...
}
獎勵:要獲得額外的榮譽,請將命令變量設置為易於更改的位置,然后將其映射到函數...
<?php
$commands = array(
'doSendEmail' => 'Send Email',
'doAddOption' => 'Add Option',
);
function doSendEmail()
{
// your email sending code here...
}
function doAddOption()
{
// your option adding code here...
}
function printForm()
{
global $commands;
?>
Name: <input type="text" name="name"><br>
Email: <input type="text" name="name"><br>
<input type="text" name="add">
<input type="submit" name="command" value="<?= $commands['doAddOption'] ?>">
<select>
<?php /* some code here */ ?>
</select>
<input type="submit" name="command" value="<?= $commands['doSendEmail'] ?>">
<?php
}
if(isset($_REQUEST['command']))
{
$function = array_search($_REQUEST['command'],$commands);
if($function !== -1)
call_user_func($function);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.