Help making button do two actions: send data and open new page

Discussion in 'HTML and CSS' started by jrlbandl, Jul 28, 2009.

  1. jrlbandl

    jrlbandl

    Joined:
    Jul 28, 2009
    Messages:
    1
    I have a contact page where I have a form setup to mail me using the mail function. It does everything it is supposed to and gives a little thanks for getting in touch by means of an echo. What I want to do now is instead of echoing the text, I want it to take the person to a completely new thanks.php page. I am a complete newbie and it is amazing that I was able to make sense of other stuff to get this to work. Please help me. It seems so simple, but everything I try doesn't work for me. Thanks. Here is all of the code that I have in the include. Oh this is php and it is in an include. Sorry.

    <?
    function spamcheck($field)
    {
    //filter_var() sanitizes the e-mail
    //address using FILTER_SANITIZE_EMAIL
    $field=filter_var($field, FILTER_SANITIZE_EMAIL);

    //filter_var() validates the e-mail
    //address using FILTER_VALIDATE_EMAIL
    if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
    else
    {
    return FALSE;
    }
    }

    //Begins by clearing the output variable
    $output = '';

    //Sets up an array of required names
    $required = array('email','name','message');

    //Creates an empty array to hold any errors
    $errors = array();

    //Check to see if the form was submitted
    if (isset($_REQUEST['submit'])) {

    //Breaks the required array into individual values
    foreach ($required as $field) {

    //If the required field is empty, adds an error message (key and value) to the error array
    if (empty($_REQUEST[$field])) {

    $errors[$field] = 'this is required';

    }
    }

    //If there are no errors
    if (count($errors)<1) {

    //Send an email with the form data or otherwise process the form data - currently this does nothing
    $to = 'jrlbandl@gmail.com';
    $subject = 'Message from BandL Contact Form';
    $from = 'From: '.$_POST['email'];
    $name = 'Name: '.$_POST['name'];
    $company = 'Company: '.$_POST['company'];
    $email = 'Email: '.$_POST['email'];
    $message = 'Message:
    '.wordwrap($_POST['message'], 70);

    $body = "$name\n$company\n$email\n\n$message";

    $break = '<br />';
    $newline = "\n";
    $message = str_replace($break, $newline, $message);

    mail ($to, $subject, $body, $from);

    $output.= '<p class="feedback">';
    $output.= 'Thank you for getting in touch. We will address this as soon as possible.';
    $output.= '</p>';

    echo $output;
    return;

    }
    }

    // If the form has not be submitted, if builds a string to display the form on the page
    $output.= '
    <form method="post" id="contactform" action="'.$_SERVER['PHP_SELF'].'"><fieldset>';

    $fields = array(
    'name' => 'text',
    'company' => 'text',
    'email' => 'text',
    'message' => 'textarea'
    );

    foreach ($fields as $field => $type) {

    $output.= '
    <label for="'.$field.'">';
    $output.= ucwords($field); //ucwords changes the text to upper-case
    if (isset($errors[$field])) {
    $output.= ' <strong class="error">is required</strong>';
    }
    $output.= '</label>';

    switch ($type) {

    case 'textarea':
    $output.= '
    <textarea name="'.$field.'" id="'.$field.'" cols="30" rows="10">';
    if (isset($_REQUEST[$field])) {
    $output.= htmlspecialchars($_REQUEST[$field]); //htmlspecialchars escapes any potentially harmful markup including < or > or \ or ' or " characters
    }
    $output.= '
    </textarea><br />';
    break;

    default:
    $output.= '
    <input type="text" name="'.$field.'" id="'.$field.'"';
    if (isset($_REQUEST[$field])) {
    $output.= ' value="'.htmlspecialchars($_REQUEST[$field]).'"';
    }
    $output.= ' /><br />';
    break;

    }


    }

    $output.= '

    <input type="submit" name="submit" value="Submit" />
    <br />
    </fieldset>
    </form>
    ';

    echo $output;

    ?>
    jrlbandl, Jul 28, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. raavi
    Replies:
    1
    Views:
    385
    Markus
    Nov 22, 2005
  2. Ice
    Replies:
    4
    Views:
    6,190
    David Dorward
    Nov 2, 2003
  3. Alex Vinokur

    Two form actions

    Alex Vinokur, Jan 14, 2005, in forum: HTML
    Replies:
    2
    Views:
    417
    Alex Vinokur
    Jan 14, 2005
  4. TrvlOrm
    Replies:
    5
    Views:
    100
    TrvlOrm
    May 6, 2004
  5. Tyrone Slothrop

    One Form, Two Targets, Two Actions

    Tyrone Slothrop, Dec 28, 2006, in forum: Javascript
    Replies:
    5
    Views:
    158
    Jonas Raoni
    Dec 29, 2006
Loading...

Share This Page