pHp Help code attached

Discussion in 'Web Design and Development' started by AFPoster, May 24, 2011.

  1. AFPoster macrumors 65816

    Joined:
    Jul 14, 2008
    Location:
    Charlotte, NC
    #1
    I just have a simple question to someone who is very familiar with php.

    Once "Submit" is selected how do I get it to direct you to this page "http://www.mysitename.com/index.php?page=thank-you" Basically with the code I supplied how do I write this in?
    I see the sections on where I am to write this all the way at the bottom of the code, just no idea how to put it in there correctly.

    Also maybe someone might know this to: I have code for a drop down box with many options to choose from already in html how do I add it to the php script so it's recognized?


    <?php

    // get posted data into local variables
    $EmailFrom = "info@mysitename.com";
    $EmailTo = "me@mysitename.com";
    $Subject = "Thank you for your interest";
    $FirstName = Trim(stripslashes($_POST['FirstName']));
    $LastName = Trim(stripslashes($_POST['LastName']));
    $Title = Trim(stripslashes($_POST['Title']));
    $Company = Trim(stripslashes($_POST['Company']));
    $Email = Trim(stripslashes($_POST['Email']));
    $Phone = Trim(stripslashes($_POST['Phone']));
    $Address = Trim(stripslashes($_POST['Address']));
    $City = Trim(stripslashes($_POST['City']));
    $State/Province = Trim(stripslashes($_POST['State/Province']));
    $Zip = Trim(stripslashes($_POST['Zip']));
    $Comments = Trim(stripslashes($_POST['Comments']));

    // validation
    $validationOK=true;
    if (Trim($FirstName)=="") $validationOK=true;
    if (Trim($LastName)=="") $validationOK=true;
    if (Trim($Title)=="") $validationOK=true;
    if (Trim($Company)=="") $validationOK=true;
    if (Trim($Email)=="") $validationOK=false;
    if (Trim($Phone)=="") $validationOK=true;
    if (!is_numeric($Phone)) $validationOK=true;
    if (Trim($Address)=="") $validationOK=true;
    if (Trim($City)=="") $validationOK=true;
    if (Trim($State/Province)=="") $validationOK=true;
    if (Trim($Zip)=="") $validationOK=true;
    if (!is_numeric($Zip)) $validationOK=true;
    if (Trim($Comments)=="") $validationOK=true;
    if (!$validationOK) {
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    exit;
    }

    // prepare email body text
    $Body = "";
    $Body .= "FirstName: ";
    $Body .= $FirstName;
    $Body .= "\n";
    $Body .= "LastName: ";
    $Body .= $LastName;
    $Body .= "\n";
    $Body .= "Title: ";
    $Body .= $Title;
    $Body .= "\n";
    $Body .= "Company: ";
    $Body .= $Company;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Phone: ";
    $Body .= $Phone;
    $Body .= "\n";
    $Body .= "Address: ";
    $Body .= $Address;
    $Body .= "\n";
    $Body .= "City: ";
    $Body .= $City;
    $Body .= "\n";
    $Body .= "State/Province: ";
    $Body .= $State/Province;
    $Body .= "\n";
    $Body .= "Zip: ";
    $Body .= $Zip;
    $Body .= "\n";
    $Body .= "Comments: ";
    $Body .= $Comments;
    $Body .= "\n";

    // send email
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

    // redirect to success page
    if ($success){
    print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
    }
    else{
    print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
     
  2. nomade macrumors member

    nomade

    Joined:
    Dec 2, 2006
    #2
    You may use :
    Code:
    header('location:index.php');
     
  3. ppc_michael Guest

    ppc_michael

    Joined:
    Apr 26, 2005
    Location:
    Los Angeles, CA
    #3
    nomade is correct. In fact, you should use header() for your other redirects as well, instead of printing <meta> refresh tags as you're doing currently.

    As for accessing the drop-down menu, it will be about the same as accessing the other form elements. For example, let's say your drop down markup looks like this:

    Code:
    <select name="dropColors">
       <option value="optionRed">Red</option>
       <option value="optionBlue">Blue</option>
       <option value="optionGreen">Green</option>
    </select>
    Your PHP would look like this:

    Code:
    <?php
    
    $chosenColor = $_POST["dropColors"];
    
    echo "User has chosen ".$chosenColor;
    If the user selected "Red" from the drop down menu, the PHP above would output

    Code:
    User has chosen optionRed
     

Share This Page