#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Meadville, Pa
    Posts
    1
    Rep Power
    0
    Hello,
    I found a form that redisplays itself with error messages for fields not
    filled in. I am trying to alter it so if the fields are filled in it will
    redirect to another page...otherwise it will display itself with error
    messages for fields not filled in.

    The redirect works now, but I am having a problem with the script displaying
    the form twice on the same page.

    The ultimate goal of this script is to:
    1) display a form
    2)display the form again with error messages if fields are left blank
    3)redirect to another page if fields are filled in

    Here is the code......I apologize for the length.

    <HTML>
    <HEAD>
    <TITLE>Feedback</TITLE>
    </HEAD>
    <BODY>

    <?

    $form_block = "

    <FORM method="POST" action="$PHP_SELF">

    <P>Your Name:<br>
    <INPUT type="text" name="sender_name"
    value="$sender_name" size=30></p>

    <P>Your E-Mail Address:<br>
    <INPUT type="text" name="sender_email"
    value="$sender_email" size=30></p>

    <P>Your Message:<br>
    <textarea name="message" cols=30
    rows=5>$message</textarea>
    </p>

    <INPUT type="hidden" name="op" value="ds">


    <P><INPUT type="submit" value="Send This Form"></p>

    </FORM>

    ";

    if ($op == "ds"){
    $send = "yes";
    header("location: <A HREF="http://www.thickbook.com");" TARGET=_blank>http://www.thickbook.com");</A>

    } else if ($op != "ds") {
    // they need to see the form
    echo "$form_block";

    // check each required field and create an error message.
    // if any of the required fields are blank, set $send to "no".

    if ($sender_name == "") {

    $name_err = "
    <font color=red>Please enter your name!</font><br>
    ";
    $send = "no";

    }

    if ($sender_email == "") {

    $email_err = "
    <font color=red>Please enter your e-mail address!</font><br>
    ";
    $send = "no";

    }

    if ($message == "") {

    $message_err = "
    <font color=red>Please enter a message!</font><br>
    ";
    $send = "no";

    }

    if ($send == "no") {

    echo "$name_err";
    echo "$email_err";
    echo "$message_err";
    echo "$form_block";

    }


    }

    ?>

    </BODY>
    </HTML>

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    16
    The header call must appear before any text is sent to the browser, i.e. before the <HTML>.

    Do your error checking at the beginnning of the document and call your header from there, if the condition suits it. You might want to send a hidden field with the form and then check for it at the top with an IF statement and do your checks within that IF block.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Indonesia
    Posts
    87
    Rep Power
    15
    Beside that you can use function isset() to check whether the field is filled or not.

    if (!isset($var))
    {
    display form

    }
    else
    {
    proceed the form

    }

    See ya !!


    ------------------
    ** It's the world of Oscario **

Similar Threads

  1. ASP.net v Oracle Forms - what is best
    By msjodin in forum Oracle Development
    Replies: 0
    Last Post: February 10th, 2004, 12:04 PM
  2. pdf forms?
    By bellcom in forum Web Design Help
    Replies: 0
    Last Post: January 31st, 2004, 10:08 PM
  3. One confirmation email, two different forms
    By sisleysusie in forum PHP Development
    Replies: 3
    Last Post: January 26th, 2004, 11:26 PM
  4. Putting/submitting lots of forms on one page
    By rampguy in forum PHP Development
    Replies: 1
    Last Post: December 5th, 2003, 11:47 PM
  5. Dynamic forms that change by user interactions?
    By BassPlayer in forum PHP Development
    Replies: 4
    Last Post: April 4th, 2003, 04:05 AM

IMN logo majestic logo threadwatch logo seochat tools logo