Results 1 to 4 of 4

Thread: Validating Form

  1. #1

    Thread Starter
    Addicted Member thamizhinpan's Avatar
    Join Date
    Dec 2005
    Location
    TE
    Posts
    243

    Validating Form

    I wish to check validation of the form by PHP (without Java script).
    But if the form doesn't validate, I can redirect the page by
    PHP Code:
    header("Location: Myform.php"); 
    this code.
    But all form fields will be reset on that time.
    So that page will not be a user friendly.
    If I can post data automatically to Myform.php I can do this simply!

    Most of the sites have the technology what I like. But I don't know how to do that!
    Can you help me to fulfill my desire please?
    If above question or answer will help to you
    Don't forget to rate me
    தமிழ்இன்பன்

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Validating Form

    Just fill out the form fields using PHP.

    PHP Code:
    <input name="field1" value="<?php echo $field1 ?>">
    Make sure that you have validated $field1 first and used the htmlentities or htmlspecialchars functions.

  3. #3

    Thread Starter
    Addicted Member thamizhinpan's Avatar
    Join Date
    Dec 2005
    Location
    TE
    Posts
    243

    Re: Validating Form

    This is my sample form

    FormPage:
    PHP Code:
      <html>
      <head>
      <title>Validating Form</title>
      </head>
      <body>
      <form action="ValidatingPage.php" method="POST">
        <P><strong>Your age:</strong><br><input name="yage" type="text"         value="<?php echo($yage);?>"></P>
        <input name="" type="submit">
        
      </form>
      </body>
    Validating Page:
    PHP Code:
    <?php
             
    if (!$_POST[yage]|| $_POST[yage]<13)
            {
                
    $yage=htmlspecialchars($_POST[yage]);
                 
    header("Location: FormPage.php");
                 exit;
            }
            else echo(
    "Form Checked");

    ?>
    Am I correct?
    But Sorry, it is not working.
    I think I must have made a mistake. But I don't know it!
    Can you able to guess it?
    If above question or answer will help to you
    Don't forget to rate me
    தமிழ்இன்பன்

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Validating Form

    If you redirect using header("Location"), then whatever data was sent through the POST request will be lost. You could make the page that has the form make the request to itself, then handle the data and if successful, then redirect to another page, if not successful, then show the data that you can get through $_POST in the appropriate fields of your form (you are in the same page again).

    That's one method...


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

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



Click Here to Expand Forum to Full Width