0

I have this form

 <form role="form" method='post' action='index.php' id='cme'>
    <input type="hidden" name="bonval" value="<?php echo $bonval ?>" />
    <fieldset>
        <h2 class="blink_me" style="color:green;font-size:40px;"><?php echo $bonval ?></h2>
        <div class="form-group">
            <center>
                <div class="g-recaptcha" data-sitekey="siteky"></div>
            </center>
        </div>
         <div class="row">
            <center>
                <input type="submit" name="claim" class="btn btn-lg btn-success btn-block" value="Claim Now" id="claim">
            </center>
        </div>
    </fieldset>
</form>

I have this javascript to disable button after click

<script>
$(function(){
    $('#claim').on('click',function(){
        $(this).val('Please wait ...')
        .attr('disabled','disabled');
        $('#cme').submit();
    });
});
</script>

and this is my form validation

 if(isset($_POST['claim'])) {
$recaptcha = $_POST['g-recaptcha-response'];
if(!empty($recaptcha)) {
    # Use the recaptcha function here
    $resp   =   getGoogleRecaptcha();
    if($resp['success']) {
        # Capture value from the form submit
        $bonval =   $_POST['bonval'];
        # Insert normally
        $db->fetchVal("insert into log (`user_id`,`amount`) values (?,?)", array($id, $bonval));
    } 
  } else { ?>
  <div class="overlay"><div class="popup" style="background:red;">
    <h2>Error</h2>
    <a class="close" href="#">&times;</a>
    <div> <center><span class="blink_me">Seems error</span></center></div>
  </div></div>  
   <?php  }
  }
  1. My issue is button gets disabled but form is not submitted
  2. if user refresh page form keeps getting submitted into database

2 Answers 2

1

Edit: sorry, lack of explanation, I read a little fast:

You can completely remove the var $ _POST after insert bdd with unset($_POST['...']);

if(isset($_POST['claim'])) {
    //code

    $db->fetchVal("insert into log (`user_id`,`amount`) values (?,?)", array($id, $bonval));

    unset($_POST['claim']);

    //code
}
Sign up to request clarification or add additional context in comments.

Comments

0

You should stop the button from submitting form first by replacing the type="submit" by type="button" :

<input type="button" name="claim" class="btn btn-lg btn-success btn-block" value="Claim Now" id="claim">

Hope this helps.

12 Comments

But form is not being sent (form validation)
$('#cme').submit() should submit the form to the php page that will make the validations not ?!
<input type="button" name="claim" class="btn btn-lg btn-success btn-block" value="Claim Now" id="claim"> added this and utton not work now and form action is self index.php page but no it does not send
Button should work normal like jsfiddle.net/jnwrc5ay/363 .. check this one using timeout just to see what happen jsfiddle.net/jnwrc5ay/364
I do not know much php or javascript so if you can do some kindness of fiddle plz to solve this issue
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.