Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-22-2010, 03:28 AM   PM User | #1
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
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) < ){ 
    
$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?
mjs is offline   Reply With Quote
Old 01-22-2010, 04:23 AM   PM User | #2
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
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.
bdl is offline   Reply With Quote
Old 01-22-2010, 04:26 AM   PM User | #3
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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?
masterofollies is offline   Reply With Quote
Old 01-22-2010, 08:14 AM   PM User | #4
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
Here i re edit the code:
PHP Code:
<? //formpwd.php
  
$password=$_POST['password'];
  if(
strlen($password) < ){ 
    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:&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..

Last edited by mjs; 01-22-2010 at 08:21 AM..
mjs is offline   Reply With Quote
Old 01-22-2010, 09:42 AM   PM User | #5
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by mjs View Post
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) < ){ 
    
$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?
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
oesxyl is offline   Reply With Quote
Old 01-22-2010, 11:19 AM   PM User | #6
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
oesxyl thank for your input, i try to adopt your code like:
PHP Code:
  $password=$_POST['password'];
  if(
strlen($password) < ){ 
  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...
mjs is offline   Reply With Quote
Old 01-22-2010, 11:53 AM   PM User | #7
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by mjs View Post
oesxyl thank for your input, i try to adopt your code like:
PHP Code:
  $password=$_POST['password'];
  if(
strlen($password) < ){ 
  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...
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:&nbsp <input type="text" name="password"value="" /></td></tr> <tr><td><input name="Send" type="submit" value="Submit" /></td></tr> </form>
        EOF;

best regards
oesxyl is offline   Reply With Quote
Old 01-22-2010, 01:49 PM   PM User | #8
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
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..
mjs is offline   Reply With Quote
Old 01-22-2010, 01:53 PM   PM User | #9
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
Most likely the HEREDOC statement has failed:
PHP Code:
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.
bdl is offline   Reply With Quote
Old 01-22-2010, 02:01 PM   PM User | #10
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
Thank for your corrections, but please tell me the more correct one, maybe i just understand if you feel free to give the sample
mjs is offline   Reply With Quote
Old 01-22-2010, 03:40 PM   PM User | #11
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
$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?
masterofollies is offline   Reply With Quote
Old 01-23-2010, 03:27 AM   PM User | #12
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
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:&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?
mjs is offline   Reply With Quote
Old 01-23-2010, 08:16 AM   PM User | #13
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
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:&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

Last edited by oesxyl; 01-23-2010 at 08:20 AM..
oesxyl is offline   Reply With Quote
Old 01-23-2010, 10:25 AM   PM User | #14
mjs
New Coder

 
Join Date: Jan 2010
Posts: 97
Thanks: 17
Thanked 0 Times in 0 Posts
mjs is an unknown quantity at this point
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.

PHP Code:
if($_POST['Send'] == 'password')
//another code.... ??? 
please tell if i do something wrong?
mjs is offline   Reply With Quote
Old 01-23-2010, 10:46 AM   PM User | #15
oesxyl
Master Coder


 
Join Date: Dec 2007
Posts: 6,682
Thanks: 436
Thanked 890 Times in 879 Posts
oesxyl is a jewel in the roughoesxyl is a jewel in the roughoesxyl is a jewel in the rough
Quote:
Originally Posted by mjs View Post
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.

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
oesxyl is offline   Reply With Quote
Reply

Bookmarks

Tags
validation submit

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 AM.


Advertisement
Log in to turn off these ads.