jquery - How do i stop duplicate entrys on a modal dialog -


what best way avoid user entering same record twice. have following in plugin

jquery(document).ready(function(){  jquery("#submit").click(function(){     var points = jquery("#points]").val();   jquery.ajax({       type: 'post',       url: myajax.ajaxurl,       data: {"action": "updateredeempoints", "points":points},       success: function(data){       alert(data);     }     });    }); 

my function posting want stop inserting db twice should produce friendly looking message box javascript default or possible use bootstrap notifications this.

wp_localize_script( 'gogreen', 'myajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php')));         function updateredeempoints(){          $userid = get_current_user_id();                 $mykey = 'player_id';         $single = true;         $playerid = get_user_meta( $userid, $mykey, $single );          $points=$_post['points'];         global $wpdb;         $wpdb->insert(              '4hsic_pods_player_ranking',              array(                  'points_to_redeem' =>$points,                 'player_id'=>$playerid,                 'date_to_be_awarded' => current_time('mysql', 1),                 'approved'=>'false'              ));          $headers  = "from: " . $form_data['name'] . " <" . $form_data['email'] . ">\n";         $headers .= "content-type: text/plain; charset=utf-8\n";         $headers .= "content-transfer-encoding: 8bit\n";          wp_mail( 'davidbuckleyni.co.uk', 'test', 'test', $headers ); 

btw using bootstrap model if makes difference.

                echo "<div id='thanks' class='modal fade' tabindex='-1' role='dialog' aria-labelledby='mymodallabel' aria-hidden='true'>";                 echo "<div class='modal-dialog'>";                 echo "<div class='modal-content'>";                 echo "<div class='modal-header'>";                 echo "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>";                 echo "<h4 class='modal-title'>redeem points</h4>";                 echo "</div>";                     echo "<form class='form-horizontal'  class='contact' name='redemmpointsform' id='redemmpointsform' >";                     echo " <div class='form-group'>";                     echo "<h3>you may redeem maxium points of : <?php echo $maxpoints;?></h3>";                     echo "<input type='hidden' name='playerid' value='<?php echo $playerid;;?>' />";                     echo "<input type='number'  valuemax='<?php echo $maxpoints;?>' name='points' id='points' class='form-control' placeholder='how many points wish redeem.' />";                     echo "<label class='control-label col-md-4' for='comments'>comments?</label>";                     echo "<input type='text' name='comments' />";                      echo "     </div>";                     echo "    <div class='form-group'>";                     echo "            <div class='col-md-6'>";                     echo "                <input type='button' class='btn btn-success' name='submit' id='submit' text='submit'>";                     echo "     <a href='#' class='btn' data-dismiss='modal'>close</a>";                     echo "         </div>";                     echo "      </div>";                     echo "</form>";                 echo "      </div>";                         echo "      </div>";                             echo "      </div>"; 

you can disable submit button before ajax request, , show message user when receive successful response server.

since using bootstrap already, use bootstrap alerts friendly success message.

for example, include

<div class="alert alert-success alert-dismissible" id="points-success" role="alert">   <button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">&times;</span></button>   <strong>success!</strong> great! points have been redeemed. </div> 

in form, hide default in css, , show in ajax success callback.

jquery(document).ready(function(){      jquery("#submit").click(function(){         var points = jquery("#points]").val();         jquery(this).prop("disabled", true);         jquery.ajax({             type: 'post',             url: myajax.ajaxurl,             data: {"action": "updateredeempoints", "points":points},             success: function(data){                  jquery("#points-success").show();             }         });    }); 

in ajax error callback, should enable button again, , display error message to user (e.g. alert-error).


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -