困惑为什么表单没有提交

时间:2011-11-29 23:35:28

标签: php html

我认为我没有遗漏任何内容,但是在提交时,表单似乎没有传输任何数据。我的代码如下,我意识到它有点长,但我想包括整个表单。所有附加函数只检查输入是否有效:

<form name="formname" id="formname" action="database.php" method = post onsubmit="return checker()">

Username: <input type='text' id='un' onchange="checkname(id)" onkeyup="checkempty(id)" ><div id="un1"></div><br>

Reporter Title:<br>

<select id="s2" onblur="checktype(id)" >

<option value="choose">Choose one</option>

<option value="Assistant Director">Assistant Director</option>

<option value="Director">Director</option>

<option value="DB Admin">DB Admin</option>

<option value="Systems Admin">Systems Admin</option>

</select><div id="s21"></div>
<br>

Password: <input type='password' id='pw' onchange="checkpass(id)" onkeyup="checkempty(id)"><div id="pw1"></div><br>

Email: <input type='text' id='eml'onchange="checkemail(id)" onkeyup="checkempty(id)"><div id="eml1"></div><br>

Description:<br> <textarea rows="6" cols="20" id="desc" onchange="checkdesc(id)" onkeyup="checkempty(id)" ></textarea><div id="desc1"></div><br>

Type of Incident:<br>

<select id="s1" onblur="checktype(id)" >

<option value="choose">Choose one</option>

<option value="afs">afs</option>

<option value="password">password</option>

<option value="hardware">hardware</option>

<option value="other">other</option>

</select><div id="s11"></div>
<br>

<?php

include("connect.php");

$ret = mysql_query("SELECT * FROM countries");

echo "Choose your location:<br>";

echo "<select id='countries' onblur='checktype(id)'>";

echo "<option value='choose'>Choose one</option>";

while($array = mysql_fetch_array($ret)){

echo "<option value='{$array['abbrevs']}'>{$array['full']}</option>";

}

echo "</select><br>";


?>

<div id="countries1"></div><br>

<p>
Would you like an email copy?


<select id="s3">

<option value="no">No</option>

<option value="yes">Yes</option>

</select>


<input type="submit" id = "sub" value= "Submit">
</p>


</form>

和我尝试用

接收它的PHP
<?php

include("connect.php");

$username = $_GET['un'];
$password = $_GET['s2'];
$reporter = $_GET['pw'];
$email = $_GET['eml'];
$description = $_GET['desc'];
$type = $_GET['s1'];
$country = $_GET['countries'];
$emailopt = $_GET['s3'];




?>

检查功能:

function checker(){

if(isgood && isgood1 && isgood2 && isgood3 && isgood4 && isgood5 && isgood6)
{
return true;
}
else{

document.getElementById('subb').style.visibility="visible";
document.getElementById('subb').innerHTML = "You must fully complete the form.";
return false;


}

其中“isgoods”只是我为验证做出的快速标记,这些标记都正常工作。

3 个答案:

答案 0 :(得分:4)

您的表单方法为POST,因此您应该在PHP脚本中使用$_POST而不是$_GET

此外,您应修改HTML以使其有效,您需要正确引用method属性:

<form name="formname" id="formname" action="database.php" method="post" onsubmit="return checker()">

答案 1 :(得分:3)

嗯,我觉得很蠢。问题是我没有提供我的HTML元素名称,而只是ID。我已经习惯了使用ajax并通过使用javascript获取值来提交,我忘记了名字O.o

答案 2 :(得分:1)

您正在使用method="POST"提交表单,因此在您的PHP中,您需要阅读POST值:

$username = $_POST['un'];
...

如果您使用method="GET"提交了表单,那么您的PHP代码就可以运行了。阅读差异here