Page 1 of 1

PHP _POST vars returning with wrong key

Posted: Mon Apr 09, 2012 5:06 am
by dave1909
When i post a form and retrieve the $_POST data, one of the keys is wrong

Code: Select all

<form name="input" action="" method="post" >
		<label for="email">Email</label><input type='email' name='email' id='email' />
			<span id='email_error'>
				<? if(isset($signup_errors)){if(array_key_exists('email',$signup_errors)){echo $signup_errors[email];}}?>
			</span>
			<br />
		<label for="password">Password</label><input type='password' name='password' id='password'  />
			<span id='password_error'>
				<? if(isset($signup_errors)){if(array_key_exists('password',$signup_errors)){echo $signup_errors[password];}}?>
			</span>
			<br />
		<label for="passwordc">Confirm</label><input type='password' name='passwordc' id='passwordc' />
			<span id='passwordc_error'>
				<? if(isset($signup_errors)){if(array_key_exists('passwordc',$signup_errors)){echo $signup_errors[passwordc];}}?>
			</span>
			<br />
		<input type='submit' id='submitform' name='s5' value='submit4' />
	</form>	
a var_dump of $_POST returns this

Code: Select all

array(3) { ["email"]=> string(13) "test@test.com" ["password"]=> string(9) "testingpw" ["pwc"]=> string(9) "testingpw" }
As you will note, there is no 'pwc' field in my form. Why is it getting 'pwc' instead of 'passwordc'

This has really baffled me, it's never happened before.

Re: PHP _POST vars returning with wrong key

Posted: Mon Apr 09, 2012 5:19 am
by azycraze
change the 'passwordc' and give some other name and see what var_dump of $_POST returns

Re: PHP _POST vars returning with wrong key

Posted: Mon Apr 09, 2012 5:25 am
by dave1909
changed form to . . .

Code: Select all

	<form name="input" action="" method="post" >
		<label for="email">Email</label><input type='email' name='email' id='email' />
			<span id='email_error'>
				<? if(isset($signup_errors)){if(array_key_exists('email',$signup_errors)){echo $signup_errors[email];}}?>
			</span>
			<br />
		<label for="password">Password</label><input type='password' name='password' id='password'  />
			<span id='password_error'>
				<? if(isset($signup_errors)){if(array_key_exists('password',$signup_errors)){echo $signup_errors[password];}}?>
			</span>
			<br />
		<label for="newvarname">Confirm</label><input type='password' name='newvarname' id='newvarname' />
			<span id='passwordc_error'>
				<? if(isset($signup_errors)){if(array_key_exists('passwordc',$signup_errors)){echo $signup_errors[passwordc];}}?>
			</span>
			<br />
		<input type='submit' id='submitform' name='s5' value='submit4' />
	</form>	

Code: Select all

array(3) { ["email"]=> string(13) "test@test.com" ["password"]=> string(9) "testingpw" ["pwc"]=> string(9) "undefined" }
Using 'Inspect element' on chrome verified that the input element has the name 'newvarname' but i still get the 'pwc' returning

Re: PHP _POST vars returning with wrong key

Posted: Mon Apr 09, 2012 5:28 am
by dave1909
Oh my, my own stupidity amazes me.

I was using jquery to submit the form and didnt change the data i was sending with the AJAX call