Page 1 of 1
Handling forms
Posted: Tue Sep 07, 2010 11:31 am
by jlimbo
Right, this is a slightly odd one but here we go. I've got a form that posts its values to a script which starts with the line
That should be as straightforward as it gets. But php tells me the index 'form' is undefined. But here's the kicker, when I look at the contents of the post array using firebug, they are as they should be with the 'form' variable present. I've checked to see if its just 'form' thats missing, but no, the entire array is empty according to php.
Anyone got any ideas what might be going on
Thanks
John
Re: Handling forms
Posted: Tue Sep 07, 2010 3:34 pm
by shawngoldw
Do this:
Code: Select all
if(isset($_POST['form'] && $_POST['form'] == 'login') {
Shawn
Re: Handling forms
Posted: Wed Sep 08, 2010 8:08 am
by jlimbo
Tried that. but the test still fails and runs the else clause.
Re: Handling forms
Posted: Wed Sep 08, 2010 10:51 am
by timWebUK
Post the code for your HTML form.
Re: Handling forms
Posted: Wed Sep 08, 2010 11:19 am
by jlimbo
Here you go
Code: Select all
<form name='loginForm' id='loginForm' class='login' action='formProcessor.php' method='post'><input type='hidden' name='form' value='login' />
<div class = 'formRow'><p>
<span class='formLeftCol'>
<label for='uname'>Username: </label>
</span>
<input type='text' name='uname' id='uname' class='formRightCol' value='' /></p>
</div>
<div class='formRow'><p>
<span class='formLeftCol'><label for='pwd'>Password: </label>
</span>
<input type='password' name='pwd' class='formRightCol' value='' /></p>
</div>
<input type='submit' value='Login' name='submit' id='submit' />
</form>
Re: Handling forms
Posted: Mon Sep 13, 2010 3:25 am
by timWebUK
You should be checking $_POST of the submit button, not the form name.
Code: Select all
if(isset($_POST['submit']))
{
//... code here
}
Re: Handling forms
Posted: Mon Sep 13, 2010 8:19 am
by jlimbo
Thanks Tim,
I've just changed that. I was actually about to mark this is resolved as I finally worked out the problem this morning. It turns the problem was purely that I hadn't added 'session_start()' in the form handler and so the query was running ok but the reponse was being lost
Thanks again
John