0
此表單驗證代碼在wordpress插件中不起作用,表單直接提交,就好像onsubmit
事件完全不存在一樣。 請幫助此表單驗證不適用於wordpress插件
<?php
/**
* Plugin Name:....
* Description:.....
* Version: Pre release
* Author:....
* Author URI:....
**/
add_action("admin_menu", "create_menus");
function create_menus()
{
add_menu_page("cash Details", "cash Details", 4, "form-page", "cash_deals_form_page");
}
function cash_deals_form_page()
{
?>
<script>
function validateForm() {
var x = document.forms["myForm"]["clientName"].value;
if (x == "") {
alert("Name must be filled out");
return false;
} else {
return confirm('Do you really want to submit this entry?');
}
}
</script>
<div style='display:inline-block; width:48%;'>
<form name="myForm" method='post' onsubmit="return validateForm()" action="<?php echo $_SERVER['REQUEST_URI'];?>">
Client Email (Type the Email Id of the client whom you want to allot cash):
<br/>
<input type='text' id='input1' name='clientName' maxlength='100'>
<br/>
<br/> Type the cash to be added in the client's account:
<br/>
<input type='number' id='input2' name='cash' min='-10000' max='100000000'>
<br/>
<br/> Type your comments here (optional):
<br/>
<textarea rows='4' cols='60' name='adminComment' maxlength='500'></textarea>
<br/>
<br/>
<input type='submit' name='submit'>
<br/>
</form>
</div>
<?php
}
?>
你期望什麼?請澄清細節。我想現在你的代碼是好的。 –
@Ataur Rahman Munna在提交第一欄空白後,我應該會收到一條警告消息,如果填寫了第一欄,我應該在提交表單之前得到確認。 – user7324674
@ user7324674,這是行爲[我得到](http://jsbin.com/wenusodixu/edit?html,output) –