Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 12-21-2006, 04:50 PM
Staff Sergeant
 
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");
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 12-21-2006, 07:28 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,036
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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 12-22-2006, 07:50 AM
Staff Sergeant
 
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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 12-22-2006, 08:23 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,036
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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 12-22-2006, 02:46 PM
Staff Sergeant
 
Join Date: Dec 2006
Posts: 43
Default Re: Go to different url with different radio button

thank you, Navaldesign. Will try out your suggestion.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 12-30-2006, 03:50 PM
Staff Sergeant
 
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 ");
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 12-31-2006, 06:20 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 9,036
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!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 09-15-2007, 07:38 PM
First Sergeant
 
Join Date: Sep 2007
Location: Montreal, Quebec
Posts: 72
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 01:07 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55