我的提交功能不起作用。提交功能不起作用
我的PHP文件有兩種形式。這兩個表單標籤都有一個onsubmit屬性,鏈接到相同的JavaScript文件。第一種形式的onsubmit正在工作。該函數由第二形式被稱爲已經簡化以這樣的:
function UserDataCheck()
{
return false;
}
form標籤是
form name='user_form' method='post' onsubmit='return UserDataCheck();'
此標記內<封閉>和雙引號,並在PHP回波-ED出文件。
請幫忙。這真讓我抓狂!之前我在UserDataCheck()中做了一些數據檢查,但是我把所有這些都去掉了,看看我是否可以使用onsubmit來阻止用戶提交!沒有成功。
以下是更多代碼!
echo "<html>";
echo "<head>";
echo "<title>Survey Form</title>";
echo "<link link rel='stylesheet' href='examples.css' type='text/css'>";
echo "</head>";
echo "<script src='validation.js'></script>";
echo "<body topmargin='20', leftmargin='20', rightmargin='20', style='background-color:beige; font-family:calibri;'>";
echo "<img src='CSE Global.jpg' width='250' height='70' align='right' />";
//---------------------------------------------------------------------
// Firstly, we determine who is using this system
// Check $_GET['dex'] for a value, if provided, then it's the user
// if not, then it's the administrator (see my notes below the code for
// more info)
//---------------------------------------------------------------------
"<input type='text' name='dex' length='50'>";
"<input type='boolean' name='sub' length='1'>";
if ($_GET['dex']=="") {
//---------------------------------------------------------------------
// $_GET['dex'] is empty so we can presume this is the Admin
//---------------------------------------------------------------------
echo "<p style='font-family:cambria;font-size:35px;'> WELCOME ADMIN!</p>";
//---------------------------------------------------------------------
// We now check to see if the form has been submitted or not ...
// To do this, we check if the variable 'sub' is in the $_POST array
//---------------------------------------------------------------------
if ($_POST['sub']!=1) {
//---------------------------------------------------------------------
// The form has not been submitted already so present the "admin form"
//---------------------------------------------------------------------
// check that they entered an amount tested, an amount passed,
// and that they didn't pass units than they more than tested
echo "<form name='admin_form' method='post' onsubmit='if(!AdminDataCheck()) return false;'>";
echo "<p><label>Scope of Service <label style='color:red'><strong>*</strong></label> <br/></label> <input type='text' name='scope' length='50' id='ScopeofService' onblur='checkScopeofService()'/><label id='labelScopeofService'></label></p>";
接下來是更多標籤和文本字段。
然後窗體標籤被關閉!
echo "<input type='hidden' name='dex' value={$dex}>";
echo "<input type='hidden' name='sub' value=1>";
echo "<input type='SUBMIT' style='background-color:white' name='submit' value='SUBMIT'>";
echo "</form>";
下面是validation.js
function AdminDataCheck()
{
var SoS = document.getElementById('ScopeofService').value;
var PNumber = document.getElementById('ProjectNumber').value;
var numericExp = /^[0-9]+$/;
var alphaExp = /^[A-Za-z ]+$/;
var Email = document.getElementById('Email').value;
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\-]+\.[a-zA-z0-9]{2,4}$/;
if (!(SoS.match(alphaExp)))
{
alert("Invalid Scope");
return false;
}
else if(!(PNumber.match(numericExp)))
{
alert("Invalid Project Number.");
return false;
}
else if(!(Email.match(emailExp)))
{
alert("Invalid Email.");
return false;
}
else
{
return true;
}
}
我要強調,這是以前的工作幾分鐘,我不需要做任何改變,只是重新啓動瀏覽器和服務器的功能!它停止工作。這真令人沮喪!
你能告訴其他人呢?你有沒有內嵌腳本的提交按鈕 – mplungjan 2012-07-11 09:21:14
這與php – albertjan 2012-07-11 09:21:21
很少有關係,請提供一些更多的表單html代碼 – MaVRoSCy 2012-07-11 09:21:36