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!
tags where appropriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hi,
i am creating a website which has a page that will allow the viewer to customise a PC. Once the options have been selected i would like to:
a) update the total cost of the pc based on the requirements. I don't know if an update is possible on the fly, i.e. as soon as the customer clicks a radio button the total is updated... although for now i don't mind having to click an update total button and displaying the new total on the same page.
b) email the requirements to myself.
I have so far created the radio buttons... same name different values etc.. and am trying to use a switch statement to test the value of the radio group. I'm not sure where to do the test (for $_POST) and how to keep the selected radio buttons selected after submitting the form to itself... instead of resetting to default.
here's some of my code:
<?php $customprice = $row_Recordset3["itemPrice"]; ?> // just getting the basic price from MySQL db
<form id="form1" name="form1" method="POST" action="$_SERVER['PHP_SELF']"> // form header
// these are some of the radio buttons
<input name="monitor" type="radio" value="radio1" checked="checked" />
15" CRT</label></td>
<input type="radio" name="monitor" value="radio2" />
17"CRT</label></td>
<input type="radio" name="monitor" value="radio3" />
...// and so on..
// here i'm trying to test for the radio buttons after submitting the form to itself.
<?php
switch($_POST['monitor']){
case 'radio1':
$customprice = $customprice - 60000;
break;
case 'radio2':
$customprice = $customprice - 80000;
break;
case 'radio3':
$customprice = $customprice - 70000;
break;
default:
$customprice = $customprice; }?>
// outputting the new price
<?php echo number_format($customprice, 2, ".", ","); ?>
ok ill start from the bottom because I am feeling a bit backwards today. to keep the selected radio button checked (assuming that your form is submitting to the page that it itself is on) do somthing like this
to email the stuff to yourself use the php mail() function because its easy
it is possible to do the update on the fly. read about ajax. but if you want to do it with only PHP then just have the total saved as a hidden field in your form and just keep giving that a new value after each time the submit button is hit and act on that hidden field with the other price information that is submitted with it to come up with the new price.
I got it working. Was pretty simple actually... now i feel dumb.
Thanx to Shiznatix for the heads up. Your code did work. My problem was that i had the submit button on the wrong form... i.e... it was on a completely seperate form from the raio buttons. DUH!!!
Anyway... here's the code for anyone who has a similar issue... although from passed experience i know my coding skills leave much to be desired. So use the code below at your own risk