How to show a php radio input value on a php email? - php

I have a php form with 4 radio inputs as below:
<?php if( $chauffeur_data['enable-paypal'] == '1' ) { ?>
<div class="radio-wrapper clearfix"><input type="radio" name="payment-method" value="paypal" <?php if( $paypal_check == '1' ) { echo 'checked="checked"'; } ?> /><label><?php esc_html_e('Pay with PayPal','chauffeur'); ?></label><img src="<?php echo plugins_url('../../assets/images/paypal.png', __FILE__); ?>"></div>
<?php } ?>
<?php if( $chauffeur_data['enable-stripe'] == '1' ) { ?>
<div class="radio-wrapper clearfix"><input type="radio" name="payment-method" value="stripe" <?php if( $stripe_check == '1' ) { echo 'checked="checked"'; } ?> /><label><?php esc_html_e('Pay with Credit Card','chauffeur'); ?></label><img src="<?php echo plugins_url('../../assets/images/stripe.png', __FILE__); ?>"></div>
<?php } ?>
<?php if( $chauffeur_data['enable-cash'] == '1' ) { ?>
<div class="radio-wrapper clearfix"><input type="radio" name="payment-method" value="cash" <?php if( $cash_check == '1' ) { echo 'checked="checked"'; } ?> /><label><?php esc_html_e('Pay with Cash to the Driver','chauffeur'); ?></label></div>
<?php } ?>
<?php if( $chauffeur_data['enable-pos'] == '1' ) { ?>
<div class="radio-wrapper clearfix"><input type="radio" name="payment-method" value="pos" <?php if( $pos_check == '1' ) { echo 'checked="checked"'; } ?> /><label><?php esc_html_e('Pay with Card on POS in the Car','chauffeur'); ?></label></div>
<?php } ?>
<?php // If all payment gateways are disabled
if( $chauffeur_data['enable-paypal'] != '1' && $chauffeur_data['enable-stripe'] != '1' && $chauffeur_data['enable-cash'] != '1' &&
$chauffeur_data['enable-pos'] != '1' ) { ?>
<input type="hidden" name="payment-method" value="cash" />
<?php } ?>
<button name="pay_now" id="pay_now" class="payment-button" type="submit">
<?php esc_html_e('Proceed To Payment','chauffeur'); ?>
</button>
<?php } else { ?>
<input type="hidden" name="payment-method" value="cash" />
<button name="pay_now" id="pay_now" class="payment-button" type="submit">
<?php esc_html_e('Proceed To Book','chauffeur'); ?>
</button>
<?php } ?>
When one of the radio buttons is checked, how can I show its value (e.g. pos) to the email I send?
The email is like below. What should be my code to show the radio button choice?
$customer_email_content .= '<li><strong>' . esc_html__('Payment Method you Selected','chauffeur') . ': </strong>' . '**payment-method-goes-here**' . '</li>'."\r\n";

After form is submitted, get the radio button value from $_POST array;
$payment_method = $_POST['payment-method'];
Use $payment_method to show the value of the radio button that is selected.
$customer_email_content .= '<li><strong>' . esc_html__('Payment Method you Selected','chauffeur') . ': </strong>' . $payment_method . '</li>'."\r\n";

Related

php .how to make make L1 statement ( if ) work?

<?php
$score=0;
$i=0;
function icremm($i) {
$Question1=array( "answer1aa","answer1b","answer1c","answer1d");
$Question2=array( "answer2a","answer2bb","answer2c","answer2d");
$Question3=array( "answer3a","answer3b","answer3c","answer3dd ");
$allquest=(array($Question1,$Question2,$Question3));
$rand1=$allquest[$i];
?>
<form method="POST">
<input type="submit" name="1b" value="<?php echo $rand1[0] ?>"/>
<input type="submit" name="2b" value="<?php echo $rand1[1] ?>" />
<input type="submit" name="3b" value=" <?php echo $rand1[2] ?>" />
<input type="submit" name="4b" value="<?php echo $rand1[3] ?>" />
</form>
<?php
echo "<br>";
global $score;
echo $score;
echo "<br>";
echo "<br>";
global $i;
echo $i;
}
icremm($i);
if (isset($_POST["1b"]) ) {
$score+=5;
$i++;
goto L1;
}
if( $i==0 && isset($_POST["2b"]) || $i==0 && isset($_POST["3b"]) ||$i==0 && isset($_POST["4b"]) ) {
header("Location: lost.php");
}
L1:{
#ob_end_clean();
icremm($i);
if (isset($_POST["2b"]) ) {
$score+=5;
$i++;
#ob_end_clean();
echo"you won";
}
}
?>
i try to make my first game like "who wants to be a millionaire" and when i answer first question and go to L1 the
first statement(//if( $i==0 && isset($_POST["2b"]) || $i==0 && //isset($_POST["3b"]) ||$i==0 && isset($_POST["4b"]) ) {
// header("Location: lost.php");) still works
but i want to L1 statement to work

Checkbox is not giving Any value after checked in

I'm trying to edit my selections using checkbox method, the values which are previously in database are checked while the other's are not. What I'm trying to do is check other checkbox or uncheck the previous selected check box but when i submit my edition nothing got happen because It is not getting values from the checkboxes I don't know why. Here is my Code. Thank you
<?php
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
$getselect=mysqli_query($con,"SELECT radio FROM institute WHERE Institute_Code='$Institute_Code'");
while($row=mysqli_fetch_array($getselect))
{ $Degree_Programs = $row ['radio'];
}}
?>
<form action="#" method="post" name="add_Institute">
<div class="container">
<!--add here-->
<?php
$char="";
$name[]="";
$j=0;
$dbvalue="";
if($Degree_Programs!=NULL )
{
$Degree_ProgramStrlen=Strlen($Degree_Programs);
for ($i=0; $i<=$Degree_ProgramStrlen; $i++)
{
$char = substr( $Degree_Programs, $i, 1 );
if($char == ',')
{
//echo $name[$j];
//$name="";
$j=$j+1;
$name[$j]="";
}
else
{
$name[$j] .= $char;
}
}
}
else
{} ?>
<!--" >-->
<div class="row col-md-offset-1">
<div class="col-md-9 ">
<?php echo "<b>Degree Programs</b>"; ?>
<br>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Arts')
$dbvalue=$name[$i];
} ?>
<label>Matric Arts</label>
<input type="checkbox" name="check_DegreePrograms[]" value="Matric Arts" <?php
$value="Matric Arts";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Science')
$dbvalue=$name[$i];
} ?>
<label for="tag_2">Matric Science</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_2" value="Matric Science" <?php
$value="Matric Science";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='FSc. Pre-Engineering')
$dbvalue=$name[$i];
} ?>
<label for="tag_3">FSc. Pre-Engineering</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_3" value="FSc. Pre-Engineering" <?php
$value="FSc. Pre-Engineering";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Fsc. Pre-Medical')
$dbvalue=$name[$i];
} ?>
<label for="tag_4">FSc. Pre-Medical</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_4" value="FSc. Pre-Medical"<?php
$value="FSc. Pre-Medical";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='I.com')
$dbvalue=$name[$i];
} ?>
</div>
</div>
<input type="Submit" name="Submit" value="Submit" class="btn btn-success pull-right"/>
</form>
</div>
<?php //} }
$pets ="";
$flag =0;
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
if (isset($_POST['Submit'])) {
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['check_DegreePrograms'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_DegreePrograms'] as $selected){
$pets .= $selected . ",";
$flag = 1;
}
}
}
if ($flag == 1) {
$pets = rtrim($pets);
}
$updated = mysqli_query($con ,"UPDATE institute set radio='$pets' where Institute_Code=1233");
if($updated)
{
echo "Data successfully updated...";
}
else {
die('Could not update data: ' . mysql_error());
}
}
}
?>
<?php
include 'footer.php';
?>'

Checking radio button on submit - PHP

I need to check a radio button input on submit.
If none of the radio buttons are checked, $err1_diet gets set to true and the red class needs to be added.
And I also need to know which radio button was checked since this isn't the only question in the form.
if( !isset($_POST['diet']) ){
$err1_diet = true;
}elseif($_POST['diet'] == 1){
$diet = true;
}else{
$diet = false;
$yes = true;
}
<p class="<?php echo (($err1_diet == true) ? "red" : "" ); ?>">• Are you on a diet?<?php var_dump($err1_diet); ?></p>
<input type="radio" name="diet" value="1" <?php echo (($diet) ? 'checked="true"' : "" ); ?> /> Yes
<input type="radio" name="diet" value="0" <?php echo (($diet) ? '' : 'checked="true"' ); ?> /> No
Actually no ... it's checking one of the radio buttons before the form is submitted. That's the problem
You can solve your problem using $_SERVER['REQUEST_METHOD']=='POST' for example:
if( $_SERVER['REQUEST_METHOD']=='POST' and !isset($_POST['diet']) ){
$err1_diet = true;
}elseif($_POST['diet'] == 1){
$diet = true;
}else{
$diet = false;
$yes = true;
}
<p class="<?php echo (($err1_diet == true) ? "red" : "" ); ?>">• Are you on a diet?<?php var_dump($err1_diet); ?></p>
<input type="radio" name="diet" value="1" <?php echo (($diet) ? 'checked="true"' : "" ); ?> /> Yes
<input type="radio" name="diet" value="0" <?php echo (($diet) ? '' : 'checked="true"' ); ?> /> No

change order of list that uses pagination

I have a paginated list that displays 10 items to a page, but I want to give the option for someone to change the order of the list, for example, by gender or age.
The pagination works, and in terms of sorting the list, so far I have:
$orderby = ($_GET['orderby'] == 'gender')? $_GET['orderby'] : 'age';
if ($result = $mysqli->query("SELECT * FROM people ORDER BY $orderby"))
With 2 basic links: gender | age
echo "<a href='{$_SERVER['PHP_SELF']}?orderby=gender'>gender</a> | <a href='{$_SERVER['PHP_SELF']}?orderby=age'>age</a>";
When I click one of the links, it changes the order of the list as required, but when I go to another page of the pagination, it does not work.
Can someone please let me know of the best way to fix this. Thanks.
Try my function genPagnation(), please refer my code below:
<?
$totalPage = 23;
$currentPage = isset($_GET['p']) && is_numeric($_GET['p']) && $_GET['p'] >= 1 ? (int)$_GET['p'] : 1;
$params = array();
$devices = array();
if( isset($_POST['order']) || isset($_GET['order']) ){
$params['order'] = isset($_POST['order']) ? $_POST['order'] : $_GET['order'];
}
if( isset($_POST['device']) || isset($_GET['device']) ){
$params['device'] = isset($_POST['device']) ? $_POST['device'] : $_GET['device'];
$devices = $params['device'];
}
for( $i = 1; $i <= $totalPage; $i++ ){
if( $i == $currentPage )
print(" <b><u>{$i}</u></b> ");
else
print(" <a href='" . genPagnation($i, $params) . "'>{$i}</a> ");
}
print("<p><hr /></p>\n\n");
function genPagnation($p, $param = array(), $pname = null, $pvalue = null){
$param['p'] = $p;
if( !empty($pname) && !empty($pvalue) )
$param[ $pname ] = $pvalue;
$query = http_build_query($param);
$query = preg_replace('/%5B[0-9]+%5D/', '%5B%5D', $query);
return '?' . $query;
}
?>
<p>
Order By:
<a href='<?=genPagnation($currentPage, $params, "order", "male")?>'>Male</a> |
<a href='<?=genPagnation($currentPage, $params, "order", "female")?>'>Female</a>
</p>
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
<p>
Filtering:
<label><input type="checkbox" name="device[]" value="iphone" <? if( !empty($devices) && in_array('iphone', $devices) ){ echo 'checked="checked"'; } ?> />iPhone</label>
<label><input type="checkbox" name="device[]" value="ipad" <? if( !empty($devices) && in_array('ipad', $devices) ){ echo 'checked="checked"'; } ?> />iPad</label>
<label><input type="checkbox" name="device[]" value="ipod" <? if( !empty($devices) && in_array('ipod', $devices) ){ echo 'checked="checked"'; } ?> />iPod</label>
<label><input type="checkbox" name="device[]" value="android" <? if( !empty($devices) && in_array('android', $devices) ){ echo 'checked="checked"'; } ?> />Android</label>
</p>
<p>
Ordering:
<label><input type="radio" name="order" value="male" <? if( isset($_REQUEST['order']) && $_REQUEST['order'] == 'male'){ echo 'checked="checked"'; } ?> />Male</label>
<label><input type="radio" name="order" value="female" <? if( isset($_REQUEST['order']) && $_REQUEST['order'] == 'female'){ echo 'checked="checked"'; } ?> />Female</label>
</p>
<p><input type="submit" value="search"></p>
</form>

How do I make values stay in chekbox?

How do I make the values stay in checkboxes?
my problem is when I submit the form the values do not stay (in the form).
Below is my code :
Mca<input type="checkbox" name="qual[]" id="Mca" value="Mca"
<?php if($qual == "Mca") { echo ' checked="checked"' ; } ?>>
Mtech<input type="checkbox" name="qual[]" id="Mtech" value="Mtech"
<?php if($qual == "Mtech") { echo "checked"; } ?>>
Btech<input type="checkbox" name="qual[]" id="Btech" value="Btech"
<?php if($qual == "Btech") { echo "checked"; } ?>>
Try this because $qual is an array.
/* Your $qual should be */ <?php $qual = $GET['qual']; ?>
<?php if($qual == "Mca")
must be changed to :
<?php if(in_array("Mca",$qual)
Try using better code for your form:
<?php
$checkboxes = array('Mca', 'Mtech', 'Btech');
foreach($checkboxes as $k => $v){
echo '<input '.($v==$qual[$k]? 'checked="checked" ': '').'type="checkbox" name="qual[]" id="'.$v.'" value="'.$v.'">';
}
?>

Categories