...

View Full Version : Validate first???



mjs
01-22-2010, 03:28 AM
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:


$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:&nbsp <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?

bdl
01-22-2010, 04:23 AM
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.

masterofollies
01-22-2010, 04:26 AM
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.

mjs
01-22-2010, 08:14 AM
Here i re edit the 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;
}
?>

<form method="post" name="frm" action="send.php" /> <tr><td>Password:&nbsp <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..:)

oesxyl
01-22-2010, 09:42 AM
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:


$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:&nbsp <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?



if(condition){
// code is executed here if condition is true
}
// code here is also executed no matter if condition is true or not




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

mjs
01-22-2010, 11:19 AM
oesxyl thank for your input, i try to adopt your code like:

$password=$_POST['password'];
if(strlen($password) < 5 ){
echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:&nbsp <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...

oesxyl
01-22-2010, 11:53 AM
oesxyl thank for your input, i try to adopt your code like:

$password=$_POST['password'];
if(strlen($password) < 5 ){
echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:&nbsp <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...


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:&nbsp <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
EOF;
}


best regards

mjs
01-22-2010, 01:49 PM
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 :confused:


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

bdl
01-22-2010, 01:53 PM
Most likely the HEREDOC statement has failed:


echo <<<EOF
<form method="post" name="form" action="send.php"/> <tr><td>Password:&nbsp <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.

mjs
01-22-2010, 02:01 PM
Thank for your corrections, but please tell me the more correct one, maybe i just understand if you feel free to give the sample :thumbsup:

masterofollies
01-22-2010, 03:40 PM
$end means it's missing a closing bracket }
So at the bottom of your script add a } once

mjs
01-23-2010, 03:27 AM
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:

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:&nbsp <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?

oesxyl
01-23-2010, 08:16 AM
try this:


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:&nbsp <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

mjs
01-23-2010, 10:25 AM
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:&nbsp <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>';

i.e.


if($_POST['Send'] == 'password')
{ //another code.... ???

please tell if i do something wrong?:)

oesxyl
01-23-2010, 10:46 AM
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:&nbsp <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>';

i.e.


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

mjs
02-02-2010, 07:16 PM
$_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 regardsOK friend, i most don't understand this and i always put "?" (questions mark) at all my statement.. that to seek any help...
thank for your nice suggestion so far, and please let us clear this posting.. another idea would be welcome

Best Regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum