simple form validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    simple form validation

    hi all

    I need to make sure someone entered some data into a form i am not concerned on this particular site about hacks or malatious injection so i just need to make sure the person entered somthing into each field. i currently send the results of my form to a remote php page. here are the names of the form fields and the basic form check as far as i have gotten. my question is if blank inputs are sent as null vlaues or if they have some random vlaue.

    [HTML]
    <form target="mailer. php" action="post">
    <input type="text" name="email">
    <input type="text" name="first_nam e">
    <input type="text" name="last_name ">
    <input type="text" name="address">
    <input type="text" name="city">
    <input type="text" name="state">
    <input type="text" name="zip_code" >
    </form>
    [/HTML]

    [PHP]
    if ($_POST[email] = WHAT GOES HERE || $_POST[first_name] || $_POST[last_name] || $_POST[address] || $_POST[city] || $_POST[state] || $_POST[zip_code])
    {
    $url= "failed.htm ";
    }

    [/PHP]

    thanks for any and all help
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Originally posted by tolkienarda
    hi all

    I need to make sure someone entered some data into a form i am not concerned on this particular site about hacks or malatious injection so i just need to make sure the person entered somthing into each field. i currently send the results of my form to a remote php page. here are the names of the form fields and the basic form check as far as i have gotten. my question is if blank inputs are sent as null vlaues or if they have some random vlaue.

    [HTML]
    <form target="mailer. php" action="post">
    <input type="text" name="email">
    <input type="text" name="first_nam e">
    <input type="text" name="last_name ">
    <input type="text" name="address">
    <input type="text" name="city">
    <input type="text" name="state">
    <input type="text" name="zip_code" >
    </form>
    [/HTML]

    [PHP]
    if ($_POST[email] = WHAT GOES HERE || $_POST[first_name] || $_POST[last_name] || $_POST[address] || $_POST[city] || $_POST[state] || $_POST[zip_code])
    {
    $url= "failed.htm ";
    }

    [/PHP]

    thanks for any and all help

    I am not quite sure what your question is. Please elaborate.

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      Originally posted by Motoma
      I am not quite sure what your question is. Please elaborate.
      ok so basicaly I need to see rather the post values i am reciving from the forms is vlaid. i dont realy care about injection or special chars or any kind of security checking i just want to know if some kind of data was entered into of each of the input boxes. if they were i want it to set $url to equal to failed.htm so i can tell the users that they need to complete the form. so the section in my code that says WHAT GOES HERE i need to know what would be sent if the input boxes were left blank

      thanks
      eric

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        To check if the user entered data for all fields, you would do something like this:
        Code:
        if(!isset($_POST['email']) || !isset($_POST['fullname']))
        {
            $url = "failure.html";
        }

        Comment

        • tolkienarda
          Contributor
          • Dec 2006
          • 316

          #5
          ah
          i always wondered what that little thing ment. well now i know

          thanks
          eirc

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            I am sorry to spoil the party, but when the user did not enter any data, but left it blank, the isset() function will return true.

            Just checking if a value (no blank) has been entered:[php]if ( strlen(trim($_P OST['email'])) < 1
            OR strlen(trim($_P OST['first_name'])) < 1
            OR strlen(trim($_P OST['last_name'])) < 1
            OR strlen(trim($_P OST['address'])) < 1
            OR strlen(trim($_P OST['city'])) < 1
            OR strlen(trim($_P OST['state'])) < 1
            OR strlen(trim($_P OST['zip_code'])) < 1 )
            {
            $url= "failed.htm ";
            } [/php]Ronald :cool:

            Comment

            • tolkienarda
              Contributor
              • Dec 2006
              • 316

              #7
              Thank ya ron

              this little script isn't done so i will be posting next time i get stuck (soon)

              thanks again
              eirc

              Comment

              Working...