NEWB- need help with form submit and math function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rkalexander
Forum Newbie
Posts: 10
Joined: Tue May 30, 2006 9:30 am

NEWB- need help with form submit and math function

Post by rkalexander »

I have a form with several pull down options that have values that are dollar amounts. On submit I would like to perform a math function to add the users selection values and then redirect to another page that itemizes the users selection and provides a total dollar amount for the price quote.

any tips or resources that anyone can direct me to?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:? I don't get it, what do you need help with? basic math?

Maybe you should post the code you have so far so we can better point you in directions..
rkalexander
Forum Newbie
Posts: 10
Joined: Tue May 30, 2006 9:30 am

Post by rkalexander »

Forgive me if I'm not asking the right question. First time posting here.

I don't know how to make it clearer than my previous post. I don't have any code to show.

I have a form with multiple selects boxes like this one:
<tr>
<td class="xl24">Family Extended Edition One time cost</td>
<td class="xl24"><select name="select">
<option value="373.75">5</option>
<option value="650.00">10</option>
<option value="1312.50">25</option>
<option value="2250.00">50</option>
<option value="3000.00">75</option>
<option value="3750.00">100</option>
<option value="9062.50">250</option>
<option value="16250.00">500</option>
<option value="28750.00">1000</option>
<option>1001+ Call for Quote</option>
</select></td>
</tr>
On submit I want to add these values based on the users selections, and then trace the amount to an online quote that is itemized and gives the sum of the total cost.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I don't think anyone here will do this for you, but I will certainly give you an idea of where to start.

Your form will need to be posted to a results page of some sort (for example, result.php). On this page, you are going to need to capture what the form sent so you can use that for your calculations. You do this by checking to see if the form was sent (doing an isset() on a $_POST var). If that if returns true, assign values to avariables from the $_POST array, then use those vars for your adding and for your display.

Code: Select all

<?php
if (isset($_POST['form_sent'])) 
{
    // Maybe use a hidden form field called form_sent to test if the form was actually posted
    $select_val_1 = $_POST['select_field_1_name'];
    $select_val_2 = $_POST['select_field_2_name'];
    $select_val_3 = $_POST['select_field_3_name'];

    $total = $select_val_1 + $select_val_2 + $select_val_3;

    echo "The first value sent was $select_val_1...<br />\n";
    echo "The second value sent was $select_val_2...<br />\n";
    echo "The third value sent was $select_val_3...<br />\n";

    echo "The total of all values sent was $total...<br />\n";
}
?>
This is very brief, but should point you in the right direction. Try some of this first, and if things go haywire, post back. Most of us here would love to help. Few of us are willing to do it for you (without getting paid).
Post Reply