Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts

    Newbie to PHP trouble with passing form variables

    I am wondering what is wrong with my script. I keep getting an error saying my variables are undefined. But I thought the variables take the value of the form elements. Is there additional code that I need to add? I am using php version 4.3.3. I have the default php.ini configurations considering i do not know how or what to change. Anywho my script is as follows:

    <?PHP

    if ($submit) { // If they've submitted the form...

    if ($customerName <= "")
    $message = "Please enter your name.";
    else if ($customerEmail <= "")
    $message = "Please enter your email address.";
    else if ($favoriteColor == "--Select--")
    $message = "Please choose a favorite color.";


    if ($message) // If we've set a message with a warning about their form entry...
    echo ($message);
    else {
    mail("MyEmail@MyDomain.com",
    "Form Results",
    "$customerName filled out the form and
    selected a favorite color of $favoriteColor",
    "From: $customerName <$customerEmail>");

    echo ("Thank you. A representative will contact you shortly.");
    die(); // We can stop if the form's been submitted and we've thanked them.
    } // end if we're sending the email

    } // end if they hit "Submit"

    ?>


    <body>
    <FORM METHOD = "post" action="formEMAILtest.php">

    <B>Your Name:</B> <INPUT TYPE = "text" NAME = "customerName" /> <BR />
    <B>Your Email:</B> <INPUT TYPE = "text" NAME = "customerEmail" /> <BR />

    <B>Your Favorite Color:</B>
    <SELECT SIZE = "1" NAME = "favoriteColor">
    <OPTION selected>--Select--</OPTION>
    <OPTION>Red</OPTION>
    <OPTION>Green</OPTION>
    <OPTION>Blue</OPTION>
    </SELECT> <BR />

    <INPUT TYPE = "submit" NAME = "submit" VALUE = "Submit Form"/> <BR />

    </FORM>
    </body>


    This is just a test form I don't care about ppl fav. color LoL.
    Last edited by StupidRalph; 09-20-2003 at 01:42 AM.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #2
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why die(); ?

    Should put if ( $submit ) {
    // Check the submission
    }
    else
    {
    // Show the form
    }


    EDIT:

    For each of the vars try using
    $oldvar = $_POST['oldvar'];

  • #3
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    thanx I'll try that now
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #4
    New to the CF scene
    Join Date
    Aug 2003
    Location
    A hole in the ground
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, in the old days we could get variables passed by forms just by using $variable_name ... but in the great NEW days here, we use $_POST[variable_name], $_GET[variable_name], $_SESSION[variable_name], etc.

    It seems like a bit of a pain compared to the old way, but TRUST me, it's MUCH better this way! Because at some point if you start mixing $_POST[username] with $_SESSION[username] with $username all in the same script, you can not only be fairly sure you end up using the right variable, you can be fairly sure the wrong one doesn't get overwritten with the wrong data.

  • #5
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And then forging login etc, and instead of a SQL query $blah people can use the GET without it being a GET

    so it is btter and a bit more secure

  • #6
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Is this correct? It keeps telling me that message has and undefined index. I lost some of the formatting due to adding color but here is the code.

    <?PHP

    $submit=$_POST['submit'];
    $customerName=$_POST['customerName'];
    $customerEmail=$_POST['customerEmail'];
    $message= $_POST['message']; $favoriteColor=$_POST['favoriteColor'];

    if ($submit) { // If they've submitted the form...


    if ($customerName <= "")
    $message = "Please enter your name.";
    else if ($customerEmail <= "")
    $message = "Please enter your email address.";
    else if ($favoriteColor == "--Select--")
    $message = "Please choose a favorite color.";


    if ($message) // If we've set a message with a warning about their form entry...
    echo ($message);
    else {
    mail("RThomas [at] Safrico.com",
    "Form Results",
    "$customerName filled out the form and
    selected a favorite color of $favoriteColor",
    "From: $customerName <$customerEmail>");

    echo ("Thank you. A representative will contact you shortly.");
    } // end if we're sending the email

    } // end if they hit "Submit"


    ?>
    Last edited by StupidRalph; 09-20-2003 at 06:42 PM.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #7
    New Coder
    Join Date
    Sep 2003
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?PHP

    $submit
    =$_POST['submit']; 
    $customerName=$_POST['customerNam
    e'
    ]; 
    $customerEmail=$_POST['customerEm
    ail'
    ]; 
    $message$_POST['message']; $favoriteColor=$_POST['favoriteCo
    lor'
    ];

    if (
    $submit) { // If they've submitted the form...


    if ($customerName <= "")
    $message "Please enter your name."
    else if (
    $customerEmail <= "")
    $message "Please enter your email address."
    else if (
    $favoriteColor == "--Select--"
    $message "Please choose a favorite color."


    if (
    $message// If we've set a message with a warning about their form entry... 
    echo ($message); 
    else { 
    mail("RThomas [at] Safrico.com"
    "Form Results"
    "$customerName filled out the form and
    selected a favorite color of $favoriteColor"

    "From: $customerName <$customerEmail>"); 

    echo (
    "Thank you. A representative will contact you shortly."); 
    // end if we're sending the email

    // end if they hit "Submit"


    ?>
    You can use the PHP tags, lemme read through

    Try making each var global, EX:
    global $submit,$customerName,$customerEmail,$message;


    Also checking if they entered a name etc use

    if (trim($thenamevar) == "") {

    trim removes spaces where they arent needed, beginning and end of text
    Last edited by Acecool; 09-20-2003 at 06:55 PM.

  • #8
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts

    Cool Thanx

    I tweaked it a lil and got it to work out thanx.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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