954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

php radio button condition

Hi
I'm trying to modify a Shipping module for an online shop but I'm not getting it to work...I want to put two options on that, if customer chooses first option he gets one price for the shipment if he chooses second option then he gets a different price.

The original module only allows one option for Shipment Method and I want to add a second option using two radio buttons.

Basically I want to check what radio button is selected and then get the value, if first radio button is checked get it's value if the second radio button is checked get the previous value plus and aditional tax.
Here goes the code:

$_SESSION[$value] = "1";
      $string = "&nbsp;<input type=\"radio\"  id=\"radio1\" name=\"shipping_rate_id\" value=\"$value\" />";
      $string .= "  Zone Shipping -  $country_name <strong><div class='zone'>". $CURRENCY_DISPLAY->getFullValue($rate )."</div></strong>";
      $string .= "&nbsp;<input type=\"radio\"  id=\"radio2\"name=\"shipping_rate_id\" value=\"$value\" />";
      $string .= "  Contra Re-embolso (+ 1.50€)<strong><div class='zone'>". $CURRENCY_DISPLAY->getFullValue($rate+1.50 )."</div></strong>";
      echo $string;
    }
	
  function get_rate( &$d ) {	
      
	  if (document.getElementById("radio2").checked) {
      $shipping_rate_id = vmGet($_REQUEST,"shipping_rate_id")+1.50;
	  $zone_arr = explode("|", urldecode(urldecode($shipping_rate_id)) );
	  $order_shipping = $zone_arr[3];
      } else {
	  $shipping_rate_id = vmGet($_REQUEST,"shipping_rate_id");
	  $zone_arr = explode("|", urldecode(urldecode($shipping_rate_id)) );
	  $order_shipping = $zone_arr[3];
	   }
	  
	  return $order_shipping;
  }
xamonix
Newbie Poster
2 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

So what is the value of $value and where would it come from? Is this a global coming from another file that includes this one?

madCoder
Junior Poster
145 posts since Feb 2010
Reputation Points: 21
Solved Threads: 37
 

on a side note. instead of escaping all of your " you can just start the string with a ' and end it with a '. I typically use ' for most things cause i have html and they have lots of ".

itisnot_me
Posting Whiz in Training
252 posts since May 2009
Reputation Points: 12
Solved Threads: 6
 
So what is the value of $value and where would it come from? Is this a global coming from another file that includes this one?

yes the value of $value is coming from another file ($value is the amount of shipping costs I had configured in the online store backoffice).

xamonix
Newbie Poster
2 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

This is php right? On line 11 you have javascript instead of php.

Assuming that vmGet() is a function for getting database safe values from user input, you can test the value of the radio button called shipping_rate_id like this:

$rate_id = vmGet($_POST, 'shipping_rate_id');
if( $rate_id == 'normal') {
  // do something
} else if($rate_id == 'taxable') {
   // do something else
}
madCoder
Junior Poster
145 posts since Feb 2010
Reputation Points: 21
Solved Threads: 37
 

This code is totally mashed. You've mixed js and php. I assume you want to use Ajax, so that the shipping price is calculated in-page when a new option is chosen. This isn't the way to do it.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: