I have a problem. I have a forum that shows a popup, when the user clicks "OK", I use ajax to switch the "1" to a "0" and the message is not shown again.
Here is my function.
`add_action( 'wp_ajax_profile_msg', 'profile_msg' );
function profile_msg() {
global $wpdb;
global $current_user;
$user = $current_user->ID;
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET usrmsg = '%d' WHERE ID = '%d'", '0', $user )); }`
Here is my Ajax.
`jQuery(document).ready(function($) {
$('.wordpress-ajax-form').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.post($form.attr('action'), $form.serialize(), function(data) {
}, 'json');
}); });`
Here is my form
`<form class="wordpress-ajax-form" method="post" action="<?php echo AJAX_URL; ?>" ><input type="hidden" name="action" value="profile_msg">
<button id="msgbutton" >OK</button>
This code actually works fine, this issue I'm having is I want to add another form to do the same thing in MySQL but a different question. I tried changing the action name, and the "wordpress-ajax-form" in the js, but it seems to be firing the first form and now my new one. I will post my new one also.
Here is my other function
`add_action( 'wp_ajax_remove_account', 'remove_account' );
function remove_account() {
global $wpdb;
global $current_user;
$id = ThemexUser::$data['active_user']['ID'];
$table_views = $wpdb->prefix . "user_views";
$table_favorites = $wpdb->prefix . "user_favorites";
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->users SET removed = '%d' WHERE ID = '%d'", '1', $id )); }`
Here is my other Ajax
`<script>
jQuery(document).ready(function($) {
$('.wordpress-ajax-form2').on('submit', function(e) {
e.preventDefault();
var $form = $(this);
$.post($form.attr('action'), $form.serialize(), function(data) {
}, 'json');
}); });
`
Here is my other form
`<form class="wordpress-ajax-form2" method="post" action="<?php echo AJAX_URL; ?>">
<input type="hidden" name="action" value="remove_account">
<button class="msgbutton" >Remove Account</button> </form>`
The first form works and the second form doesn't work, I'm new to this so be gentle.
Thanks.