Passing html values to scripts

chriso0258 16 May, 2012
I am experimenting with combo boxes and made a simple drop down selection box. The field name is membership and the "Options" for the drop down box are:
10=Individual
100=Patron
300=Patron King
500=Patron Master
1000=Patron Grandmaster


I ran the debugger to see what's what. Here is the debugger info:
Array
(
    [option] => com_chronoforms
    [tmpl] => component
    [chronoform] => drop_down_box
    [event] => submit
    [Itemid] => 
    [membership] => 500
    [submit] => Submit
    [f64a5f48673cc4b3412733dd1641609b] => 1


Ultimately I will want to pass some values to Paypal. The variable "item_name" is what shows up as what the user purchased. So, what I am wanting to accomplish is to create a variable "item_name" and have it correlate to the type of membership (Individual, Patron, etc) so the user can see what they purchased.

Unless there is an easier way, I am figuring I will need to use the "Custom Code" action and create an if, elseif statement in order to create the "item_name". I was going to use php but am open to something else if it's easier. I am thinking along the following line of code:

<?php
$membership={membership};
if ($membership==10)
  $item_name="Individual Membership";
elseif ($membership==100)
  $item_name="Patron Membership";
elseif ($membership==300)
  $item_name="Patron King Membership";
elseif ($membership==500)
  $item_name="Patron Master Membership";
elseif ($membership==1000)
  $item_name="Patron Grandmaster Membership";
echo $item_name;
?>


What I haven't figured out yet is how to pass the value of the combo box "membership" value to the script (in this example it is 500). The script works if I hard code the value.
<?php
$membership=500;
if ($membership==10)...


Is this the easiest way to accomplish what I want? If so, how do I pass the value? If there is a simpler way, please let me know.

Thanks.
chriso0258 16 May, 2012
Ok, I just figured it out. I need to use:

$membership=$_POST['membership'];


So, is this the easiest/best way to do what I'm doing? I'm all for using the KISS approach.

But now, how do I now pass the php variable $item_name to the redirect URL? I'm using a custom code in the onSubmit section.

<head>
<body>
<?php
$membership=$_POST['membership'];
$item_name="";

echo "<h3>the membership value is: $membership</h3>"; /*I use this to verify that the
                                   membership variable is being passed, which it is. */
if ($membership==10)
  $item_name="Individual Membership";
elseif ($membership==100)
  $item_name="Patron Membership";
elseif ($membership==300)
  $item_name="Patron King Membership";
elseif ($membership==500)
  $item_name="Patron Master Membership";
elseif ($membership==1000)
  $item_name="Patron Grandmaster Membership";
?>
<form>
<input type="hidden" name="item_name" value="<?php $item_name;?>">
</form>
</body>
</head>


The Debugger confirms that the "membership" value is being passed. But the item_name remains blank. Obviously, I'm missing something.
GreyHead 17 May, 2012
Hi Chris0258,

There are a few ways of doing this depending on where the original data is. I'd probably do this here - a variant on your code - in a Custom Code action in the On Submit event:
<?php
$memberships = array (
  '10' => 'Individual',
  '100' => 'Patron',
  '300' => 'Patron King',
  '500' => 'Patron Master',
  '1000' => 'Patron Grandmaster'
);
$form->data['item_name'] = $memberships[$form->data['membership']];
?>

Then you can use both {item_name} and {membership} in the template, etc.

Bob
chriso0258 17 May, 2012
Thanks Bob. I appreciate your tactfulness and patience when dealing with my sloppy code.
This topic is locked and no more replies can be posted.