【发布时间】:2016-02-01 10:49:35
【问题描述】:
避免用户两次输入相同记录的最佳方法是什么。我的插件中有以下内容
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);
}
});
});
我的函数只是发布到我想阻止它两次插入数据库,但它应该产生一个比 javascript 默认值更友好的消息框,或者是否可以使用引导通知。
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 );
顺便说一句,如果它有所作为,我正在使用引导模型。
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 only redeem the 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 do you wish to 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>";
【问题讨论】:
标签: jquery wordpress twitter-bootstrap wordpress-theming