Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-22-2010, 03:28 AM
PM User |
#1
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
Validate first???
I apologize in advance because this is going to be a bit foolish question.
Thank you so much for any advice on this.
here my code:
PHP Code:
$password = $_POST [ 'password' ];
if( strlen ( $password ) < 5 ){
$messages []= '( Please enter password of more than 5 character length )' ;
$inputIsValid = false ;
}
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
when i click the submit button why directly to send.php and avoid all validation field?
01-22-2010, 04:23 AM
PM User |
#2
Regular Coder
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
I'm sensing that English may be a second language here; can you restate your question?
BTW, you should not name your entities using the same token, e.g. a FORM element named 'form' is a bad idea.
01-22-2010, 04:26 AM
PM User |
#3
Senior Coder
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
Hi,
To find out why it's bypassing the validation, you need to post your whole code, or at least the parts that are related to this.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
01-22-2010, 08:14 AM
PM User |
#4
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
Here i re edit the code:
PHP Code:
<? //formpwd.php
$password = $_POST [ 'password' ];
if( strlen ( $password ) < 5 ){
echo ( " Please enter password of more than 5 character length " );
// $messages[]='( Please enter password of more than 5 character length )';
// $inputIsValid=false;
}
?>
Quote:
<form method="post" name="frm" action="send.php" /> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
@ bdl
how bad is using the same name Token and the element?
@ masterofollies
Imagine that's all. i just try created a small code as a sample before go to next large code. but let's solve by the fallowing current code..
how to validate first after click the submit button then the next step go to send.php. Thank you for your next advance..
Last edited by mjs; 01-22-2010 at 08:21 AM ..
01-22-2010, 09:42 AM
PM User |
#5
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
mjs
I apologize in advance because this is going to be a bit foolish question.
Thank you so much for any advice on this.
here my code:
PHP Code:
$password = $_POST [ 'password' ];
if( strlen ( $password ) < 5 ){
$messages []= '( Please enter password of more than 5 character length )' ;
$inputIsValid = false ;
}
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
when i click the submit button why directly to send.php and avoid all validation field?
PHP Code:
if( condition ){
// code is executed here if condition is true
}
// code here is also executed no matter if condition is true or not
PHP Code:
if( condition ){
// code is executed here if condition is true
exit;
}
// code here is not executed if condition is true because of exit
best regards
01-22-2010, 11:19 AM
PM User |
#6
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
oesxyl thank for your input, i try to adopt your code like:
PHP Code:
$password = $_POST [ 'password' ];
if( strlen ( $password ) < 5 ){
echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
EOF;
exit;
}
// $messages [] ='( Please enter password of more than 5 character length )';
// $inputIsValid=false;
echo (" <BR />Please enter password of more than 5 character length ");
but i think i do something wrong there. because no happens...
01-22-2010, 11:53 AM
PM User |
#7
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
mjs
oesxyl thank for your input, i try to adopt your code like:
PHP Code:
$password = $_POST [ 'password' ];
if( strlen ( $password ) < 5 ){
echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
EOF;
exit;
}
// $messages [] ='( Please enter password of more than 5 character length )';
// $inputIsValid=false;
echo (" <BR />Please enter password of more than 5 character length ");
but i think i do something wrong there. because no happens...
PHP Code:
if(empty( $_POST )){
if(isset( $_POST [ 'password' ]) && strlen ( $_POST [ 'password' ]) < 5 ){
$messages []= '( Please enter password of more than 5 character length )' ;
}else{
// do something when password is >= 5
}
echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
EOF;
}
best regards
01-22-2010, 01:49 PM
PM User |
#8
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
so many thanks for your last code, but i getting errors on it:
Parse error: syntax error, unexpected $end in C:\xampp\htdocs\shop\test.php on line 12
PHP Code:
<? // line 1
if(empty( $_POST )){
if(isset( $_POST [ 'password' ]) && strlen ( $_POST [ 'password' ]) < 5 ){
$messages []=( Please enter password of more than 5 character length
bla ... bla ... etc
?>
<--- here line 12
anything else?
Last edited by mjs; 01-22-2010 at 01:55 PM ..
01-22-2010, 01:53 PM
PM User |
#9
Regular Coder
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
Most likely the HEREDOC statement has failed:
PHP Code:
echo <<<EOF <form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form> EOF;
The closing
EOF statement has to be all the way to the left without any indentation.
01-22-2010, 02:01 PM
PM User |
#10
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
Thank for your corrections, but please tell me the more correct one, maybe i just understand if you feel free to give the sample
01-22-2010, 03:40 PM
PM User |
#11
Senior Coder
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
$end means it's missing a closing bracket }
So at the bottom of your script add a } once
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
01-23-2010, 03:27 AM
PM User |
#12
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
thank you friend for your help so far, but i think it's not about bracket, the bracket is enough, something wrong in using HEREDOC, then i change it like:
PHP Code:
if(empty( $_POST )){
if(isset( $_POST [ 'password' ]) && strlen ( $_POST [ 'password' ]) < 5 ){
$messages []= '( Please enter password of more than 5 character length )' ;
}else{
// do something when password is >= 5
}
echo '
<form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>' ;
//exit;
//}
}
but nothing happens, any another idea?
01-23-2010, 08:16 AM
PM User |
#13
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
try this:
PHP Code:
if(isset( $_POST [ 'password' ]) && strlen ( $_POST [ 'password' ]) < 5 ){ $messages []= '( Please enter password of more than 5 character length )' ; }else{ echo 'do something when password is >= 5, redirect to next page for example' ; } if(empty( $_POST ) || (isset( $_POST [ 'password' ]) && strlen ( $_POST [ 'password' ]) < 5 )){ echo ' <form method="post" name="form" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>' ; //exit; //} }
was my fault, because I used only empty($_POST) as condition the form was processed only first time( when the post array was empty)
best regards
Last edited by oesxyl; 01-23-2010 at 08:20 AM ..
01-23-2010, 10:25 AM
PM User |
#14
New Coder
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
i most appreciate your advance.. but i still get no luck with these code..
That important firstly to indicate the
name of submit button?
<form method="post" name="frm" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="
Send " type="submit" value="Submit" /></td></tr> </form>';
i.e.
PHP Code:
if( $_POST [ 'Send' ] == 'password' )
{ //another code.... ???
please tell if i do something wrong?
01-23-2010, 10:46 AM
PM User |
#15
Master Coder
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
Quote:
Originally Posted by
mjs
i most appreciate your advance.. but i still get no luck with these code..
That important firstly to indicate the
name of submit button?
<form method="post" name="frm" action="send.php"/> <tr><td>Password:  <input type="text" name="password"value="" /></td></tr> <tr><td><input name="
Send " type="submit" value="
Submit" /></td></tr> </form>';
i.e.
PHP Code:
if( $_POST [ 'Send' ] == 'password' )
{ //another code.... ???
please tell if i do something wrong?
$_POST['Send'] will be 'Submit' after submit, look to your form, you can't mix names and values anyway.
Same thing for any form element, it's a pair name, value. After submit you will find the name as key in $_POST/$_GET and it's value as $_POST['form_element_name'].
You don't know basic things, this is not a problem but stop when you don't understand something and try to find yourself the answer or ask and I will try to help.
best regards
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 03:07 AM .
Advertisement
Log in to turn off these ads.