0

Here is my code for my form:

<form method = "get">
    <div class="row">
        <div class="input-field col s12 ">
            <input id="notes" name = "notes" type="text" class="validate">
            <label for="notes">Notes</label>
        </div>
    </div>
    <div class="row">
        <div class="input-field col s12">
            <i class="material-icons prefix">credit_card</i>
            <input id="card_details" type="text" inputmode="numeric" pattern="[0-9]+" onkeypress='return event.charCode >= 48 && event.charCode <= 57' autocomplete="cc-number" maxlength="16" data-length="16" placeholder="xxxx xxxx xxxx xxxx">
            <label for="card_details">Card details</label>
            </div>
    </div>
    <div class="row">
        <div class="input-field col s6">
            <i class="material-icons prefix">web_asset</i>
            <input id="expiration_date" type="tel" pattern="[0-9]*" inputmode="numeric">
            <label for="expiration_date">Expiration (mm/yy)</label> 
        </div>
        <div class="input-field col s6">
            <input id="card_ccv" type="text" inputmode="numeric" pattern="[0-9\s]{3,4}"  onkeypress='return event.charCode >= 48 && event.charCode <= 57' autocomplete="cc-number" maxlength="3" data-length="3" placeholder="xxx">
            <label for="card_ccv">Security Code</label>
        </div>
    </div>
    <div class="row center">
        <button class="btn waves-effect waves-light cyan" type="submit" onclick= order_placed()>Pay
            <i class="material-icons right">arrow_right</i>
        </button>
    </div>
</form>

What I am trying to achieve is to be able to send the "notes" input into this AJAX call to be handled.

<script type="text/javascript"> 

    <?php $notes = $_GET['notes']?>
    function order_placed() {
        $.ajax({
            url: 'payment.php?notes=<?php $notes?>',
            type: 'GET',
            success: function(result){
                alert(result)
                window.location.assign("home.html")
            }
        })
    }
</script> 

The code does work, however, it takes two clicks at the submit button for the form to be handled. On the first click, the form empties itself with the URL of the page becoming "/checkout.php?notes=whatevernotesis". On the second click, the original notes form is sent to be handled.

Any help will be appriciated.

sparrowe
  • 3
  • 2
  • PHP can only see the result of `$_GET['notes']` *after* the form has been submitted; to look at the value *without* submitting to the server, you need to write that in JavaScript, not PHP. – IMSoP Feb 13 '22 at 20:31
  • _Side note:_ You may have been premature in deleting your linked list question: https://stackoverflow.com/questions/74339628/popping-in-c-linked-list-returns-aborted-when-theres-nothing-in-the-list You deleted it about 30 seconds before I could post my complete answer. Because you deleted it, this is the only way I can communicate this. – Craig Estey Nov 06 '22 at 21:54
  • @CraigEstey deleted since I realised my mistake right after that lol – sparrowe Nov 10 '22 at 17:17

0 Answers0