Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    mjs
    mjs is offline
    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) < ){ 
        
    $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?

  • #2
    bdl
    bdl is offline
    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.

  • #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?

  • #4
    mjs
    mjs is offline
    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) < ){ 
        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..
    Last edited by mjs; 01-22-2010 at 08:21 AM.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #6
    mjs
    mjs is offline
    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) < ){ 
      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...

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #8
    mjs
    mjs is offline
    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.

  • #9
    bdl
    bdl is offline
    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:&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.

  • #10
    mjs
    mjs is offline
    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

  • #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?

  • #12
    mjs
    mjs is offline
    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:&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?

  • #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:&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.

  • #14
    mjs
    mjs is offline
    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:&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?

  • #15
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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


  •  
    Page 1 of 2 12 LastLast

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •