PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 4, 2022

[FIXED] How to show a php radio input value on a php email?

 July 04, 2022     email, forms, input, php, radio-button     No comments   

Issue

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";

Solution

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";


Answered By - Ravinder Reddy
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing