views:

77

answers:

3

Hi,

I have a HTML form, which includes radio buttons that the user can select if he wants to sign up for multiple years in order to get a discount. At the moment, i have a PHP if statement that basically says IF the user selects yes for the discount, calculate the price, display details in a table, perform SHA1HASH conversion, and then display details in a hidden form (this form must be sent to our payment partners.

ELSE (if the user selects no), basically the same as above, but obviously values will be different.

My problem is the HTML table and forms have to be outside the PHP which means that when I run the page, both the forms, and tables appear. Is there any way around this?

+1  A: 
<form action=''>
<input type="radio" value="1" name="radiobutton">YES</input>
<input type="radio" value="0" name="radiobutton">NO</input>
</form>

if(isset($_POST['radiobutton'])
 {
    echo 'Value YES'; 
    // your code here
    ?>

    <!---- HTML HERE ------>

    <!---- END  HTML ------>

    <?php

 }

Make sure your form has the

 action=''

function empty, it will load the same page if you will leave it empty.

Jordy
It should be `action=''` I think..
halfdan
Because my answer wasn't an answer, thats why.
Jordy
@Jordy Sorry, I tough you where the person who asked the question.
HoLyVieR
@ HoLyVieR, Aah, no problem.
Jordy
+1  A: 

If I understand what you are trying to do correctly. You want to put a check around the HTML you want displayed after the form is submitted.

<? if (isset($_POST["option"])) { ?>
   <!-- HTML HERE -->
<? } ?>

This will keep the HTML code inside the if statement from displaying until after the form is submitted.

All you have to do is change you POST value to one of your form controls.

Robert Greiner
+2  A: 

You can have an if/else encapsulating the HTML.

<?php
if($userHasDiscount==true) {
    include 'discounttable.html';
}
else {
    include 'standardtable.html';
}

Mind you that you should follow MVC and adopting a framework (say CodeIgniter) will lead you in the right direction to solve this sort of problems.

Frankie
This sounds like a good way to go actually! Just a quick question - say I'm inserting variables into this hidden form, and into my html table - Will I still be able to do this?
TaraWalsh
`($userHasDiscount==true)` why not just `($userHasDiscount)`. No need to use `(true/false == true)`, it is better to use just `(true/false)`.
Alex
@TaraWalsh if you are inserting variables into the form, you'll include `discounttable.php` and not `.html`. All variables will be available on the included page.
Alex
Thanks Alex and Frankie. This seems the most easiest solution for me right now.
TaraWalsh
@Alex thks for pointing that up! Wrote it that way for readability, in my code I tend to adopt your way.
Frankie