Check radio get value to array

i have input radio as:

input type="radio" name="payvalue" value="126500000"br
input type="radio" name="payvalue" value="252000000"br
input type="radio" name="payvalue" value="503000000" checkedbr

and a href get value to payment as

a target="_blank" href="https://www.demo.com/[email protected]=GET_VALUE_OF_RADIO"Pay Now/a

How to change input radio get value of check to price=GET_VALUE_OF_RADIO

Any idea for hepls me. Thanks

Topic radio php Wordpress javascript

Category Web


First, let's put all the "payvalue" radio options into an array. This will allow us to then display them all using a foreach loop to reduce redundancy and the chance to make a mistake:

$payValueOptions = [126500000, 252000000, 503000000];

Now, let's render the fields in a foreach loop:

$selectedPayValue = $_GET['price'];

foreach ($payValueOptions as $option):
    $isChecked = ($selectedPayValue == $option);
    ?>

    <input type="radio" name="payvalue" value="<?php echo $option; ?>" <?php $isChecked ? 'checked' : '' ?>><br>

    <?php
endforeach;

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.