-3

I have this piece of coding, i am attempting to change the form action dynamically depending on a current selection on the form. if a user selects 'paypal' I want the action to be set to <?php echo ci_site_url(); ?>corders/buy/<?php echo $order_id; ?> and something else if a user selects 'card'. I have tried to set it using a variable '$post_order' but its not working.

How can i do this, i am a php newbie so this might be a stupid question to many? my code:

<div class="row ops-sm-10 mx-auto">

   <form role=form action="<?php $post_order;?>" method="POST" id="PaymentMethodForm">
       <label for="PaymentMethod">Choose a payment method:</label>
        <select name="PaymentMethod" onchange="" id='PaymentMethod'>
            <option value="">--Choose a payment method--</option>
            <option value="card">card</option>
            <option value="paypal">paypal</option>
        </select>
    <div>
        <button type="submit">Safe Checkout</button>
    </div>
    </form>
    <?php $selectedmethod = filter_input(INPUT_POST, 'PaymentMethod');?>
    
        <?php if ($selectedmethod == 'paypal'): ?>
            <?php $post_order = "<?php echo ci_site_url(); ?>corders/buy/<?php echo $order_id; ?>" 
            ?>
            
            <p>You selected Paypal </p>

                
        <?php elseif ($selectedmethod == 'card'): ?>
            <p>You selected card</p>
        <?php endif ?>
</div>
Muhuri.JSON
  • 117
  • 11
  • 1
    You'll need javascript. PHP runs before the page is sent to the browser, javascript after, so by the time the user sees the page, PHP is done. – aynber May 09 '22 at 14:20
  • 1
    Mandatory reading in this regard: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/q/13840429/1427878) – CBroe May 09 '22 at 14:21
  • @aynber Thank you for the comments. Any javascript i can try or checkout. I will appreciate – Muhuri.JSON May 09 '22 at 14:27

0 Answers0