I need help with a php form script please.

Discussion in 'PHP' started by Art White, Apr 8, 2011.

  1. #1
    This is the end of the script:-
    /* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
    if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
    echo "<h4>Invalid email address</h4>";
    echo "<a href='java_script:history.back(1);'>Back</a>";
    }
    elseif ( preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email ) ) {

    echo "<h4>characters not allowed in this field</h4>";
    echo "<a href='java_script:history.back(1);'>Back to e mail form</a>";

    }

    elseif ($email == "") {
    echo "<h4>You must enter an e mail address</h4>";
    echo "<a href='java_script:history.back(1);'>Back to e mail form</a>";
    }
    /* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */

    elseif (mail($recipient,$email,$message, $from)) {
    // Where to redirect after form is processed.
    echo "<h4>Thank you</h4>";
    } else {
    echo "<h4>Can't send email</h4>";
    }


    ?>


    I want the form to put up an html confirmation page - which also has normal menu links to continue using the website.
    From what I can read..

    header("Location: http://www.example.com/page.html"); exit;

    this should go in at the end of the script to function.

    putting in before the ?> does not work.

    I know basically nothing about PHP scripting.

    Any help appreciated

    TIA

    Art
     
    Art White, Apr 8, 2011 IP
  2. NathanFalkner

    NathanFalkner Peon

    Messages:
    28
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Very generally speaking, it appears the portion of code you posted
    attempts to validate that the submitted input on the form is "valid"
    and then sends an e-mail.

    It also sounds like you want to insert this code...

    header("Location: http://www.example.com/page.html"); exit;
    Code (markup):
    ...somewhere at the "end" of the script so that presumably the
    user is re-directed back to a specific page after the script sends out
    the e-mail. Or something like that. I'm just not sure.

    But assuming that's what you want to have happen, I'd try replacing
    this line of code...

    echo "<h4>Thank you</h4>";
    Code (markup):
    ...with this line of code...

    header("Location: http://www.example.com/page.html"); die();
    Code (markup):
    Try that and see what happens, good luck!
     
    NathanFalkner, Apr 10, 2011 IP
  3. Art White

    Art White Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Thanks for your reply...... however, I have tried that previously and it does not work, and your amendment to "); die(); give the same none result as exit.


    The result is - instead of getting the dark grey PHP page withe the "Thank you" msg - its just blank. The form is sent - but leaves the less informed with - to them - no guiding menu, yes they can use the browser back button - but I have to contend with the user perhaps - either not wanting to do that (!) or not knowing how to.
    I also think the sender would appreciate a return to the form page and a menu to other area's.

    I had put up a modified " reply form" which returned to the sending page. BUT the items showed in the email as

    qty XXXX
    Item XXXXX

    and they wanted
    Qty xxxx Item XXXXXX

    to avoid "confusion !

    Thanks for your reply

    Art
     
    Last edited: Apr 10, 2011
    Art White, Apr 10, 2011 IP