Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: adding another function to the form

  1. #1
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default adding another function to the form

    I am very new to php, so, any help is much appreciated.

    I have a simple contact form. I would like to add one function to it.
    If the radio button (mailing list) is checked "YES" is it possible to open another url after submitting the form?

    here is the link to the form:
    http://www.knitsandpieces.com/contact_TEST.htm

    and here is the php code:

    <?php
    $to = $_REQUEST['sendto'] ;
    $from = $_REQUEST['Email'] ;
    $name = $_REQUEST['Name'] ;
    $headers = "From: $from";
    $subject = "Web Contact Data";

    $fields = array();
    $fields{"Name"} = "Name";
    $fields{"Company"} = "Company";
    $fields{"Email"} = "Email";
    $fields{"Phone"} = "Phone";
    $fields{"list"} = "Mailing List";
    $fields{"Message"} = "Message";

    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    $headers2 = "From: noreply@YourCompany.com";
    $subject2 = "Thank you for contacting us";
    $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com";
    if($from == '') {print "You have not entered an email, please go back and try again";}
    else {
    if($name == '') {print "You have not entered a name, please go back and try again";}
    else {
    $send = mail($to, $subject, $body, $headers);
    $send2 = mail($from, $subject2, $autoreply, $headers2);
    if($send)
    {header( "Location: http://www.knitsandpieces.com/thankyou.htm" );}
    else
    {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
    }
    }
    ?>

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Do you mean if its checked, don't send the mail, direct to blah.com?
    If so, add:
    PHP Code:
    if(isset($_POST['check_name'])){
      
    header("Location: blah.com");

    Jeremy | jfein.net

  3. #3
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Not quite. I mean, send the e-mail and then go to another place (another url).

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Here:
    Code:
    if($send) 
    {header( "Location: http://www.knitsandpieces.com/thankyou.htm" );}
    It looks like your directing them, do you want it to be: If its checked, instead of redirecting to: http://www.knitsandpieces.com/thankyou.htm, redirect to: http://www.knitsandpieces.com/thankyou1.htm?
    Jeremy | jfein.net

  5. #5
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, this will work too. If checked I want them to go to thankyou1, if not to thankyou2.
    How should I do it?

    Thank you very much!

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Change:
    Code:
    if($send) 
    {header( "Location: http://www.knitsandpieces.com/thankyou.htm" );} 
    else 
    {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
    With:
    Code:
    if($send)
    if(isset($_POST['check'])){
      $direct_to = 'thanks1';
    } else {
      $direct_to = 'thanks';
    }
    {header( "Location: ".$direct_to );} 
    else 
    {print "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
    Jeremy | jfein.net

  7. #7
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face

    I inserted the new code, but it is not working. I am sorry, I guess, I am doing something wrong here. Could you, please, check. And thank you for your patience - I am very new to this.


    if($send)
    if(isset($_POST['check'])){
    $direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
    } else {
    $direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
    }
    {header( "Location: ".$direct_to );}
    else
    {print "We encountered an error sending your mail, please notify info@dekko2.com"; }
    }
    }
    ?>

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Make sure that you have a checkbox with the name of 'check' or change the highlighted below to the name it should be:
    Code:
      if ($send) {
          if (isset($_POST['check'])) {
              $direct_to = 'http://www.knitsandpieces.com/thankyou.htm';
          } else {
              $direct_to = 'http://www.knitsandpieces.com/thankyou2.htm';
          }
      {
          header("Location: " . $direct_to);
      } else {
          print "We encountered an error sending your mail, please notify info@dekko2.com";
      }
    }
    }
    ?>
    Jeremy | jfein.net

  9. #9
    Join Date
    Jan 2009
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry:

    it is giving me the error:

    Parse error: syntax error, unexpected T_ELSE in /var/www/html/kn/knitsandpieces.com/contact.php on line 34

  10. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Sorry, since you put in the '}' I thought I needed it, here:
    PHP Code:
    <?php
      
    if ($send) {
          if (isset(
    $_POST['check'])) {
              
    $direct_to 'http://www.knitsandpieces.com/thankyou.htm';
          } else {
              
    $direct_to 'http://www.knitsandpieces.com/thankyou2.htm';
          }
          {
              
    header("Location: " $direct_to);
          } else {
              print 
    "We encountered an error sending your mail, please notify info@dekko2.com";
          }
      }
    ?>
    Jeremy | jfein.net

Bookmarks

Posting Permissions

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