Forms PHP IF Statement
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 SHA1HA开发者_开发问答SH 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?
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.
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.
<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.
精彩评论