Results 1 to 4 of 4

Thread: Form warning?

  1. #1
    Join Date
    Jun 2003
    Location
    New York
    Posts
    189

    Form warning?

    I have a script i've written, it's a simple contact form that sends email to me from users input. I have some if() statements in there that make sure the user fills in all the fields. I'm using the POST method so when the user hits submit the script checks to make sure all fields are filled in, if one is empty it displays a message on the page asking to go back and fill it in.

    Example:

    PHP Code:
    if (!strlen($_POST['name'])){
                print 
    '<br><br><br>
            <table border="1" bordercolor="black" width="300">
            <tr>
            <td bgcolor=silver><div align=center>Please enter your name.<br>
            <A HREF="javascript:history.go(-1);">Back to the previous page.</A></div>
            </td>
            </tr>
            </table>'
    ;
            exit;
            } 
    Now this is what I want to fix, right now the user has to click submit and gets sent to another page to find out he has an error, when they go back, their info isn't in the fields anymore, so I would like to have the warning just be a pop up box saying "please fill iin xxx field. thank you" then they just click ok on the box and have the chance to fill in the field before getting on to the next page. I hope that made sense..
    John DeLutri
    President - Lightning Technologies, Inc.

    Web hosting is simple math: Fast+Reliable+Service=Happy Customer

  2. #2
    Join Date
    Sep 2002
    Location
    Illinois
    Posts
    2,307
    You have two choises here

    1) JavaScript method
    2) PHP method

    1) This method will check if fields are enter before form is submitted

    Here is an example

    http://www.w3schools.com/js/tryit.as...s_formvalidate

    2) You will need to use a script that checks the form values after submit. If error occurs script should return user back to the form and fill the form with the values that user already entered.

    Hope this helps

    null
    How's my programming? Call 1-800-DEV-NULL

  3. #3
    Join Date
    Jun 2003
    Location
    New York
    Posts
    189
    Thanks, I'll look into that.
    John DeLutri
    President - Lightning Technologies, Inc.

    Web hosting is simple math: Fast+Reliable+Service=Happy Customer

  4. #4
    Join Date
    Mar 2003
    Location
    MD
    Posts
    640
    If I am reading this right, you are wanting to do something like this in regards to PHP.

    PHP Code:
    <?php
    if (!submit) {
         if (!
    strlen($_POST['field1']) || !strlen($_POST['field2'])) {
              
    //error line goes here
         
    } else {
              
    //mail function goes here
         
    }
    }
    ?>
    I can't think right this moment so there might be an error or so but hopefully this will help.

Posting Permissions

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