Page 2 of 2

Posted: Tue Mar 13, 2007 1:18 pm
by Art Shotwell
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


How about this? This would allow me to pass the 'totalamount' to the next page, but not the description. 

[syntax="html"]<form action="order.php" method=post>

<p><strong>United States delivery address  (We add sales tax for Washington state shipping addresses)</strong></p>

<p><input type=radio name="totalamount" value="28.00">1 year - $28.00<br> 
<input type=radio name="totalamount" value="53.50">2 years - $53.50<br> 
<input type=radio name="totalamount" value="79.00">3 years - $79.00</p>

<p><strong>If your subscription will be delivered to Washington state, use these choices</strong></p>

<p><input type=radio name="totalamount" value="30.49">1 year - $28.00<br> 
<input type=radio name="totalamount" value="58.27">2 years - $53.50<br> 
<input type=radio name="totalamount" value="86.04">3 years - $79.00</p>

<p><strong>Foreign & Canada</strong></p>

<p><input type=radio name="totalamount" value="32.00">1 year - $32.00<br> 
<input type=radio name="totalamount" value="61.50">2 years - $61.50<br> 
<input type=radio name="totalamount" value="91.00">3 years - $91.00</p>

<p><strong>First Class</strong></p>

<p><input type=radio name="totalamount" value="42.00">U.S. & Canada: 1 year - $42.00<br> 
<input type=radio name="totalamount" value="64.00">Foreign: 1 year - $64.00</p>

<p><input type=submit name="submit" value="Continue"> <input type=reset value="Clear"></p>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Mar 13, 2007 2:16 pm
by RobertGonzalez
Anything captured in a form can be passed to a server side script via the POST array. That means you can literally take anything that is in a form and capture it in the resulting page of the action URL of the form element provided you are using the post method, also found in the form element.

That said, you should be able to very easily assign values based on what was passed in the form, including if the user is coming from Washington, then apply whatever processing (math, for instance) is needed, then echo that data in another page.

Posted: Tue Mar 13, 2007 2:46 pm
by Art Shotwell
But, I can't have multiple values for a single input name, right?
Everah wrote:Anything captured in a form can be passed to a server side script via the POST array. That means you can literally take anything that is in a form and capture it in the resulting page of the action URL of the form element provided you are using the post method, also found in the form element.

That said, you should be able to very easily assign values based on what was passed in the form, including if the user is coming from Washington, then apply whatever processing (math, for instance) is needed, then echo that data in another page.

Posted: Tue Mar 13, 2007 2:55 pm
by RobertGonzalez
Not unless that input is an array.

Posted: Tue Mar 13, 2007 3:03 pm
by Art Shotwell
Everah wrote:Not unless that input is an array.
I've got a PHP book here and been reading about arrays. I'll do a bit more reading, but so far I haven't figured out how to make them work in this case.

Posted: Tue Mar 13, 2007 3:41 pm
by RobertGonzalez
Say you are using checkboxes...

Code: Select all

<form>
<input type="checkbox" name="check_this[1]" />Check 1<br />
<input type="checkbox" name="check_this[2]" />Check 2<br />
<input type="checkbox" name="check_this[3]" />Check 3<br />
<input type="checkbox" name="check_this[4]" />Check 4<br />
<input type="submit" name="Send" value="Send This" />
</form>
You could access the checkbox array like this:

Code: Select all

<?php
// This is not the best way, but it works for now
if (isset($_POST['Send'])) {
  // This will be an array
  $checks = $_POST['check_this'];
  if (!empty($checks)) {
    for ($i = 0; $i < 4; $i++) {
      if (isset($checks[$i])) {
        echo "Check box number $i was set<br />";
      }
    }
  } else {
    echo 'There were no check boxes checked.';
  }
}
?>

Posted: Tue Mar 13, 2007 4:49 pm
by Art Shotwell
Okay, I guess I just don't get it. I understand checkboxes. What I'm looking for is passing multiple (hidden) values for a single input. A user sees "check here for 1 year subscription, $28." But, in addition to passing $28 as the amount, I'd like to pass a description "1 year subscription to magazine" that I can display on the next page, and pass along to credit card folks as a description.

Posted: Tue Mar 13, 2007 5:20 pm
by RobertGonzalez

Code: Select all

<form method="post" action="/path/to/your/php/processsing/page.php">
<input type="hidden" name="description" value="1 year subscription to magazine" />
<input type="submit" name="Send" value="Send This" />
</form>

Code: Select all

<?php
// This is not the best way, but it works for now
if (isset($_POST['Send'])) {
  $desc = '';
  if (isset($_POST['description'])) {
    $desc = $_POST['description'];
  }

  echo $desc . ' is the description passed';
}
?>
Keep in mind that echoing data passed by a form is very dangerous unless you take precautions to filter the data for XSS, SQL and other type of injections. this example is just a low security way of showing how passing hidden values work. Hidden elements and values, by the way, are the passed same way as an elements and values for non-hidden elements.

Posted: Tue Mar 13, 2007 5:51 pm
by Art Shotwell
It sounds like you're suggesting a separate buy (or submit) button for each subscription rate. Far as I can tell, that's the only way I can use hidden values for individual items. I had thought I'd use radio buttons for a buyer to select from, then hit a buy button, but it looks like I could achieve the same thing with a separate buy button for each subscription rate. I was looking for something more elegant. I'll work on new code tomorrow...got company coming tonight. The only thing I'm missing that I'd like is some way to automatically add 8.9% to the total amount if someone says they're in Wash. state.

A separate buy button would be a separate form for each button, right?

Posted: Tue Mar 13, 2007 6:02 pm
by RobertGonzalez
Not necessarily. There are easy ways to do what you want. As for the text rate...

Code: Select all

<?php
// You need to devise way of finding out which state the user is from
// Then check to see if that state is washington
// if it is, multiply the price by 0.089 to get the tax
if ($state == 'washington') // or something to this effect
{
  // Calculate the tax
  $tax = $price * 0.089;

  // Format the tax to n,nnn.nn format
  $tax = number_format($tax, 2, '.', ',');

  // Now add the tax to the total
  $total = price + $tax;

  // And format the total to n,nnn.nn format
  $total = number_format($total, 2, '.', ',');
}
?>
Again, these are pointers, not actually pluggable code.

Posted: Tue Mar 13, 2007 6:58 pm
by Art Shotwell
Everah wrote:Not necessarily. There are easy ways to do what you want. As for the text rate...
If so, it's not apparent to me.

Posted: Thu Mar 15, 2007 10:13 am
by Art Shotwell
Okay, I give up. I don't understand enough PHP to write this. I'm going to look for someone to hire to write the code for me. If it's as simple as some here say, it shouldn't cost too much. And, maybe I'll learn something from it, too. I appreciate that a couple folks chimed in here trying to help out.