1

I don't think there's anything I left out, but the form doesn't seem to be transmitting any data upon hitting submit. My code is as follows, I realize it's kind of long, but I wanted to include the entire form. All of the attached functions just check if the input was valid:

<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>

and the php I tried to receive it with

<?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'];




?>

the checker function:

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;


}

where the "isgoods" where just quick flags I made for validations, which was all working properly.

Sam
  • 2,309
  • 9
  • 38
  • 53

3 Answers3

4

Your form's method is POST so you should use $_POST instead of $_GET in your PHP script.

Also you should fix up your HTML so it's valid, you need to quote the method attribute properly:

<form name="formname" id="formname" action="database.php" method="post" onsubmit="return checker()">
Clive
  • 36,918
  • 8
  • 87
  • 113
  • I actually don't believe that's it, since I tried that originally and it still didn't work. Could it have anything to do with my onsubmit function? It simply returns true if the form's fields are valid, but does that prevent it from submitting? – Sam Nov 29 '11 at 23:48
  • Returning true won't stop it submitting does the function return false at any point (I guess it probably does) Does the page actually refresh when you submit the form? – Clive Nov 29 '11 at 23:50
  • The page should only return false when any of the fields are not valid, and yes it does refresh when I hit submit and all fields are valid. Could it have anything to do with that the form is within a php file? (since it had to connect to a DB for a dynamic list of countries) – Sam Nov 29 '11 at 23:53
  • Not really, HTML is perfectly valid inside a PHP file as long as it's outside ` – Clive Nov 29 '11 at 23:56
3

Well, I feel stupid. The problem was that I didn't give my HTML elements names, but rather just IDs. I was so used to using ajax and submitting by just getting the value with javascript via the ID that I forgot about names O.o

Sam
  • 2,309
  • 9
  • 38
  • 53
1

You are submitting your form with method="POST", so in your PHP you need to read the POST values:

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

Had you submitted your form with method="GET", your PHP code would work. Read about the difference here.

Community
  • 1
  • 1
James Skidmore
  • 49,340
  • 32
  • 108
  • 136