Connecting Tech Pros Worldwide Forums | Help | Site Map

How to Modify my PHP form to ADD 3 Options?

Newbie
 
Join Date: Oct 2009
Posts: 2
#1: Oct 12 '09
Hello,

I am looking to create this function (3 options): https://www.securebiller.com/proresvera.com/order.php

Where customers can choose 3 different options, but my PHP currently only allows one option: http://www.nutraiq.com/index2.php

Questions:
1. How can I take the submit button I currently have <input name="amt" type="hidden" id="amt" value="62.53"> and change the "value" to something that I can add a "Check Box or Radio button" and add 3 options on my page then have it submit that value?

2. The other issue is that the my index2.php page will send an EMAIL with the original "Value" shown; could you also suggest a "code" to add to the EMAIL that would reflex the customers choice.

EMAIL PHP SAMPLE:
$MailBody = $MailBody . " <p>Please keep this email for your records and print it for future reference. You will see a non-refundable charge for the $62.53 on your credit card statement under the marketing firm’s name of “NGO PRODUCT” or “NGO PRODUCTS ONLINE” depending on your credit cards reporting system. So, be aware that this is a PAYMENT for your 90-Day Supply of NUTRAiQ Nutrient Rich Shampoo.</p>\r\n";

3. Then I need a "code" to add to my "thankyou" page where the "$62.53" can be replaced by the customers choice.
http://www.nutraiq.com/payment-complete.php


Thanks in Advance!

TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 919
#2: Oct 12 '09

re: How to Modify my PHP form to ADD 3 Options?


0. Welcome to Bytes.

1. You want to look at javascript for that. Javascript handles actions once the page has been sent and the user is looking at it. To use PHP, you would need to send the page again, which would involve sending the form, but that's a bit overkill. AJAX is like a hybrid, but is not needed. So using javascript you can use user events (like clicking a radio button or changing a dropdown) to do something (like change your "amt" value).

2. Once your form has been submitted, the data from your form is sent in a $_POST array. To access your $_POST variables your would have something like:
Expand|Select|Wrap|Line Numbers
  1. $amt = $_POST['amt'];
So the name of the form element is the "key" of the array. If you haven't done much of this before you should really spend some time reading about PHP forms.

3. Again, this is form handling, so once your form is finished, you can set what it displays and include something like:
Expand|Select|Wrap|Line Numbers
  1. if ($successful) {
    echo "Thanks for your \$$amt!";
    }
The "\$" is to escape the $ character (which is usually for variables) and the next $amt is for the variable previously defined.

4. You said that the input you described what your submit button? It's type is "hidden" so it will not display, and if it was a submit button teh type would be "submit"? Which do you want?
Newbie
 
Join Date: Oct 2009
Posts: 2
#3: Oct 13 '09

re: How to Modify my PHP form to ADD 3 Options?


Thanks TheServant for your time.

In regards to your question about the button, if you go to my site you'll see the HTML code for the button: http://www.nutraiq.com/index2.php

HTML CODE:
<td height="25" colspan="2"><div align="center">
<input name="amt" type="hidden" id="amt" value="62.53">
<input type="image" src="images/button-60day-submit.jpg" width="224" height="49"></div></td>

My Goal is for my site to look like: https://www.securebiller.com/proresvera.com/order.php

ABOUT javascript:
In regards to the Javascript, could you please show me the JS you have in mind to add and how I can put the two elements together, i.e. "amt" and the 3 options as "My Goal" example is doing?

Thanks again for your time.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 919
#4: Oct 13 '09

re: How to Modify my PHP form to ADD 3 Options?


Have a look at this to get s similar code to what you will need. Simply copying the code will not help and you should try to understand it and teach yourself a bit of basic javascript so you can get it working exactly how you want it.

You can change the style of a submit button, which is better (I think atleast) than using an image input.
Expand|Select|Wrap|Line Numbers
  1. /* HTML */
  2. <input name="submit" type="submit" id="submit_button" value="" />
  3.  
  4. /* CSS */
  5. #submit_button {
    color: red;
  6. background: yellow url(images/button-60day-submit.jpg) no-repeat;
  7. height: 49px;
  8. width: 224px;
  9. }
That's for your submit button. Now you can leave your hidden one to use later. Now I have to ask, why don't you process which radio button was selected once the form is submitted and do the calculation in PHP?

As in, you don't use javascript, or a hidden input but have PHP do it when you process the form like:
Expand|Select|Wrap|Line Numbers
  1. $amt = $_POST['radio_value'] * 0.834; /* Or whatever your calculation is */
This is the better choice if you're not displaying the update everytime a user clicks on a different radio button, which you're not if your input is hidden.

Have a look at this to get you started on PHP forms if you haven't already.
Reply