Hi,
I have next to no experience using php. I've been through some basic tutorials which I think I understand but I've been asked to build a form which I thought would be basic but I cannot figure it out. Can someone help?
I suggest making a new php file (f.e. calculate.php)
So that when you press Submit button the values of the selected objects are sent to the calculate.php
Based on those values calculate.php can descide what is the answer.
That's a good start point and a good practice!
Later you can just change file name so that you submit the given values to the same php file, and make IT calculate the answer using same method you did in calculate.php
so if I set the action of my form to calculate.php I can set all the variables etc. in the new file and then echo them in my original form?
I've made a start trying to get my form working using switch. My thinking is if I can get one dropdown working I can build on that and add the other two:
[html]
<?php
switch ($choose_sizes) {
case 'Small':
echo '<input type="text" name="total" value="90" />';
break;
case 'Medium':
echo '<input type="text" name="total" value="95" />';
break;
case 'Large':
echo '<input type="text" name="total" value="100" />';
break;
}
?>
[\html]
I'm thinking that if $choose_sizes takes its values from the drop down 'choose_sizes' then if I select Medium it should display the text area with 95 in it. Unfortunately I can't get this to work. It just doesn't display anything.
You don't need to calculate values for each of them.
When you make a selection in your form and press Calculate button, all values are sent, in your case it is still "#".
So if you change action into action="calc.php" and press button Calculate those values that are selected will be sent to the calc.php. Then you can use (in calc.php):
$size = $_POST["choose_sizes"];
to get the size that was selected. (Egzample if $size == 0 then user selected small, if $size == 1 then user selected medium etc..)
This way you can find values that have been submited and then using them descide what is the cost.
Bookmarks