Results 1 to 8 of 8

Thread: Go to different url with different radio button
      
   

  1. #1
    Join Date
    Dec 2006
    Posts
    43

    Default Go to different url with different radio button

    I intend to add two radio/option buttons to Davidundalicia's contact_us form template (see below in blue). What I need is that after clicking "Send Now", those users who selected Radio Button A will be directed to URL A and those selected Radio Button B will be directed to URL B. What should I add to the php file to make this possible?

    <?PHP
    // Receiving variables
    @$name = addslashes($_POST['name']);
    @$email = addslashes($_POST['email']);
    @$comments = addslashes($_POST['comments']);
    // error checking
    if (strlen($name) == 0 )
    {
    header("Location: name_error.html");
    exit;
    }
    if (strlen($email) == 0 )
    {
    header("Location: email_error.html");
    exit;
    }
    if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
    {
    header("Location: email_error.html");
    exit;
    }
    if (substr_count($comments, '@') > "2")
    {
    header("Location: comments_error.html");
    exit;
    }
    //Sending Email to form owner
    $mailto = "your email address here";
    $mailsubj = "Feedback from my website form";
    $mailhead = "From: $email\n";
    reset ($HTTP_POST_VARS);
    $mailbody = "Values from my website form:\n";
    while (list ($key, $val) = each ($HTTP_POST_VARS))
    {
    if ($key!="submit")
    {
    $mailbody .= "$key : $val\n";
    }
    }
    mail($mailto, $mailsubj, $mailbody, $mailhead);
    // Autoresponder
    $mailto = $email;
    $mailsubj = "Copy of the info you Submitted";
    $mailhead = "From: website form\n";
    mail($mailto, $mailsubj, $mailbody, $mailhead);
    header("Location: confirmationpage.html");
    ?>

  2. #2
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,080

    Default Re: Go to different url with different radio button

    Let's suppose that you will name your Radio Button "choice", and the two values are "A" and "B". You code should become:

    <?PHP
    // Receiving variables
    @$name = addslashes($_POST['name']);
    @$email = addslashes($_POST['email']);
    @$comments = addslashes($_POST['comments']);

    @$choice = addslashes($_POST['choice']);

    if ($choice == "A") {
    $redirecturl =" www.yourdomain.com/page_for_choice_A.html "
    }
    elseif ($choice == "B") {
    $redirecturl = " www.yourdomain.com/page_for_choice_B.html "
    }
    else {
    $redirecturl = " www.yourdomain.com/default_redirect_page.html "
    }



    // error checking
    if (strlen($name) == 0 )
    {
    header("Location: name_error.html");
    exit;
    }
    if (strlen($email) == 0 )
    {
    header("Location: email_error.html");
    exit;
    }
    if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
    {
    header("Location: email_error.html");
    exit;
    }
    if (substr_count($comments, '@') > "2")
    {
    header("Location: comments_error.html");
    exit;
    }
    //Sending Email to form owner
    $mailto = "your email address here";
    $mailsubj = "Feedback from my website form";
    $mailhead = "From: $email\n";
    reset ($HTTP_POST_VARS);
    $mailbody = "Values from my website form:\n";
    while (list ($key, $val) = each ($HTTP_POST_VARS))
    {
    if ($key!="submit")
    {
    $mailbody .= "$key : $val\n";
    }
    }
    mail($mailto, $mailsubj, $mailbody, $mailhead);
    // Autoresponder
    $mailto = $email;
    $mailsubj = "Copy of the info you Submitted";
    $mailhead = "From: website form\n";
    mail($mailto, $mailsubj, $mailbody, $mailhead);
    header("Location: $redirecturl ");
    ?>

    Change
    yourdomain.com/page_for_choice_A.html , yourdomain.com/page_for_choice_B.html , and yourdomain.com/default_redirect_page.htmlwith the actual pages where your visitors must be redirected after the submission. The default page can be the same or different from the two others.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  3. #3
    Join Date
    Dec 2006
    Posts
    43

    Default Re: Go to different url with different radio button

    1. When using radio buttons, either choice A or B will be select, then what is the purpose for the code below?

    else {

    $redirecturl = " www.yourdomain.com/default_redirect_page.html "
    }

    2. when processing the php file, does it process the code from top to bottom? If yes, should the error checking process come before the redirect instruction, so that all errors are checked before the users are directed to respective url?

  4. #4
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,080

    Default Re: Go to different url with different radio button

    1. Your radio buttons might be selected by default or not. So, with two radio buttons, you have three available options: A, B, or none. I just gave you a code that covers all three cases. If you dont need the third option, simply don't use it.

    Make the code like this:
    @$choice = addslashes($_POST['choice']);

    if ($choice == "A") {

    $redirecturl =" www.yourdomain.com/page_for_choice_A.html " ;
    }
    if ($choice == "B") {
    $redirecturl = " www.yourdomain.com/page_for_choice_B.html " ;
    }


    2. Yes. the redirect command is in the very bottom line. The above is only the code defining the redirect url, according to the radio button choice.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  5. #5
    Join Date
    Dec 2006
    Posts
    43

    Default Re: Go to different url with different radio button

    thank you, Navaldesign. Will try out your suggestion.

  6. #6
    Join Date
    Dec 2006
    Posts
    43

    Default Re: Go to different url with different radio button

    After adding in the "redirecturl", the following error occurred. How should I amend it?

    "Parse error: syntax error, unexpected '}' in /home/dhuhmhsc/public_html/cancelprocessing.php on line 32"

    (Error highlighted in red below)

    <?PHP
    // Receiving variables
    @$first_name = addslashes($_POST['first_name']);
    @$last_name = addslashes($_POST['last_name']);
    @$email = addslashes($_POST['email']);
    @$cancel = addslashes($_POST['cancel']);
    @$feedback = addslashes($_POST['feedback']);
    // error checking
    if (strlen($first_name) == 0 )
    {
    header("Location: name_error.html");
    exit;
    }
    if (strlen($last_name) == 0 )
    {
    header("Location: name_error.html");
    exit;
    }
    if (strlen($email) == 0 )
    {
    header("Location: email_error.html");
    exit;
    }
    if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))
    {
    header("Location: email_error.html");
    exit;
    }
    //Trial or cancel
    if ($cancel == "trial") {
    $redirecturl =" www.horsedummies.com/thankyou.html " ;
    }
    if ($cancel == "cancel") {
    $redirecturl = " https://www.paypal.com/cgi-bin/websc...edummies%2ecom " ;
    }
    //Sending Email to form owner
    $mailto = "cancel_feedack@horsedummies.com";
    $mailsubj = "Cancel Feedback from my website form";
    $mailhead = "From: $email\n";
    reset ($HTTP_POST_VARS);
    $mailbody = "Values from my website form:\n";
    while (list ($key, $val) = each ($HTTP_POST_VARS))
    {
    if ($key!="submit")
    {
    $mailbody .= "$key : $val\n";
    }
    }
    mail($mailto, $mailsubj, $mailbody, $mailhead);
    header("Location: $redirecturl ");
    ?>

  7. #7
    Join Date
    Oct 2005
    Location
    Italy
    Posts
    12,080

    Default Re: Go to different url with different radio button

    There is nothing wrong with the code, apart the fact that you have missed the last line, which should redirect the visitor after submission:

    header("Location: $redirecturl ");

    Make sure that what you have posted above is what you have actually uploaded (in php a dot or a comma may result in errors). Or, if you wish, send me your loggin details and i'll have a look.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!


  8. #8
    Join Date
    Sep 2007
    Location
    Montreal, Quebec
    Posts
    70

    Default Re: Go to different url with different radio button

    Hi there,

    I tried to create a simple form with a radio button and two choices in addition to a submit button. I simply want my client to identify himself as either A or B and based on the information A or B, he should be directed to a page with a form for A or a Form for B.

    I solved the problem with a hyper link, but I wanted to learn how I may do so with a radio button instead.

    Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Posting Permissions

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