Jump to content

asifmohammed1978

New Members
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About asifmohammed1978

  • Rank
    Newbie
  1. Hi All, Apologies for the delayed response, so maybe I need to go back to basics. I have a WP theme that allows a user to click a heart icon and that triggers an update into the MySQL DB. However what I want to do is remove the user having to click so the MYSQL DB is updated automatically. The update only needs to take place once after 3 seconds and never again, additionally I don't need it remove the update as the current functionality does. As you can see I'm seriously basic in my coding skills, hopefully the above and below makes it easier to help me. Thank you in advance, being really cheeky, full code snippets would be great so I can copy paste but also learn so I don't bug anyone again. author.php page code:-------------------------------------------- <form class="ajax-form" action="<?php echo AJAX_URL; ?>" method="POST"> <?php if(ThemexUser::islastviewed(ThemexUser::$data['active_user']['ID'])) { ?> <a href="#" title="<?php _e('Remove from lastviewed', 'lovestory'); ?>" data-title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button current"></a> <input type="hidden" class="toggle" name="user_action" value="remove_lastviewed" data-value="add_lastviewed" /> <?php } else { ?> <a href="#" title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" data-title="<?php _e('Remove from Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button"></a> <input type="hidden" class="toggle" name="user_action" value="add_lastviewed" data-value="remove_lastviewed" /> <?php } ?> <input type="hidden" name="user_lastviewed" value="<?php echo ThemexUser::$data['active_user']['ID']; ?>" /> <input type="hidden" class="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" /> <input type="hidden" class="action" value="<?php echo THEMEX_PREFIX; ?>update_user" /> </form> themex.user.php: -------------------------------------------- public static function getUser($ID, $extended=false) { $data=get_userdata($ID); if($data!=false) { $user['login']=$data->user_login; $user['email']=$data->user_email; } $user['ID']=$ID; $user['status']=self::getStatus($ID); $user['profile']=self::getProfile($ID); if($extended) { $user['lastviewed']=themex_keys(ThemexCore::getUserMeta($ID, 'lastviewed', array())); } return $user; } public static function updateUser() { $data=$_POST; if(isset($_POST['data'])) { parse_str($_POST['data'], $data); $data['nonce']=$_POST['nonce']; check_ajax_referer(THEMEX_PREFIX.'nonce', 'nonce'); self::refresh(); } if(isset($data['user_action']) && wp_verify_nonce($data['nonce'], THEMEX_PREFIX.'nonce')) { $redirect=false; switch(sanitize_title($data['user_action'])) { case 'register_user': self::registerUser($data); break; case 'login_user': self::loginUser($data); break; case 'reset_password': self::resetPassword($data); break; case 'update_profile': self::updateProfile(self::$data['user']['ID'], $data); break; case 'add_lastviewed': self::addlastviewed(self::$data['user']['ID'], $data['user_lastviewed']); break; case 'remove_lastviewed': self::removelastviewed(self::$data['user']['ID'], $data['user_lastviewed']); $redirect=true; break; case 'update_settings': self::updateSettings(self::$data['user']['ID'], $data); break; case 'update_status': self::updateStatus(self::$data['user']['ID']); break; } if($redirect) { wp_redirect(themex_url()); exit(); } } } /** Checks user last viewed */ public static function islastviewed($ID) { if(isset(self::$data['user']['lastviewed'][$ID])) { return true; } return false; } /** Adds user lastviewed */ public static function addlastviewed($ID, $user) { if(!isset(self::$data['user']['lastviewed'][$user])) { array_unshift(self::$data['user']['lastviewed'], array( 'ID' => "$ID", 'date' => current_time('timestamp'), )); ThemexCore::updateUserMeta($user, 'lastviewed', self::$data['user']['lastviewed']); } } /** Removes user last viewed */ public static function removelastviewed($ID, $user) { if(isset(self::$data['user']['lastviewed'][$user])) { unset(self::$data['user']['lastviewed'][$user]); ThemexCore::updateUserMeta($ID, 'lastviewed', self::$data['user']['lastviewed']); } } /** Gets user settings */ public static function getSettings($ID) { $settings=ThemexCore::getUserMeta($ID, 'settings', array( 'favorites' => ThemexCore::getOption('user_settings_favorites', 1), 'lastviewed' => ThemexCore::getOption('user_settings_lastviewed', 1), 'photos' => ThemexCore::getOption('user_settings_photos', 1), 'gifts' => ThemexCore::getOption('user_settings_gifts', 1), 'notices' => 1, )); return $settings; } /** Updates user settings */ public static function updateSettings($ID, $data) { $settings=array(); //lastviewed if(isset($data['user_lastviewed'])) { $settings['lastviewed']=intval($data['user_lastviewed']); } //password if(isset($data['user_password']) && !empty($data['user_password'])) { if(strlen($data['user_password'])<4) { ThemexInterface::$messages[]=__('Password must be at least 4 characters long', 'lovestory'); } else if(strlen($data['user_password'])>16) { ThemexInterface::$messages[]=__('Password must be not more than 16 characters long', 'lovestory'); } else if(preg_match("/^([a-zA-Z0-9]{1,20})$/", $data['user_password'])==0) { ThemexInterface::$messages[]=__('Password contains invalid characters', 'lovestory'); } else if($data['user_password']!=$data['user_password_repeat']) { ThemexInterface::$messages[]=__('Passwords do not match', 'lovestory'); } else { wp_set_password($data['user_password'], $ID); wp_set_auth_cookie($ID, true); ThemexInterface::$messages[]=__('Password has been successfully changed', 'lovestory'); $_POST['success']=true; } } ThemexCore::updateUserMeta($ID, 'settings', $settings); self::$data['user']['settings']=self::getSettings($ID); if(empty(ThemexInterface::$messages)) { ThemexInterface::$messages[]=__('Settings have been successfully saved', 'lovestory'); $_POST['success']=true; } } jquery.interface.js: -------------------------------------------- var themeElements = { submitButton: '.submit-button', ajaxForm: '.ajax-form', } //AJAX Form $(themeElements.ajaxForm).each(function() { var form=$(this); form.submit(function() { var message=form.find('.message'), loader=form.find('.loader'), toggle=form.find('.toggle'), button=form.find(themeElements.submitButton), title=form.find(themeElements.submitButton).data('title'); var data={ action: form.find('.action').val(), nonce: form.find('.nonce').val(), data: form.serialize() } loader.show(); button.addClass('disabled').toggleClass('current'); if(!message.hasClass('static')) { message.slideUp(300, function() { $(themeElements.colorboxLink).colorbox.resize(); }); } jQuery.post(form.attr('action'), data, function(response) { if(jQuery('.redirect', response).length) { if(jQuery('.redirect', response).attr('href')) { window.location.href=jQuery('.redirect',response).attr('href'); } else { window.location.reload(); } message.remove(); } if(title) { button.data('title', button.attr('title')); button.attr('title', title); } toggle.each(function() { var value=toggle.val(); toggle.val(toggle.data('value')); toggle.data('value', value); }); loader.hide(); button.removeClass('disabled'); if(response!='' && response!='0' && response!='-1') { if(message.hasClass('popup')) { $.colorbox({html:'<div class="popup">'+response+'</div>'}); } else if(message.hasClass('static')) { message.append(response); } else { message.html(response).slideDown(300, function() { $(themeElements.colorboxLink).colorbox.resize(); }); } } form.find('.temporary').val(''); form.find('.scroll').each(function() { $(this).scrollTop($(this)[0].scrollHeight); }); }); return false; }); }); //Submit Button $(themeElements.submitButton).not('.disabled').click(function() { var form=$($(this).attr('href')); if(!form.length || !form.is('form')) { form=$(this).parent(); while(!form.is('form')) { form=form.parent(); } } form.submit(); return false; });
  2. Basically Im looking to auto submit the entry to the DB, I don't think I need all the code either, but not sure how to amend as I only need it to add and will never need it to remove. Thank you
  3. Hi, Thank you. See below. I'm doing the changes in the php file directly. <form id="lastviewer" class="ajax-form" action="<?php echo AJAX_URL; ?>" method="POST"> <?php if(ThemexUser::islastviewed(ThemexUser::$data['active_user']['ID'])) { ?> <a href="#" title="<?php _e('Remove from lastviewed', 'lovestory'); ?>" data-title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button current"></a> <input type="hidden" class="toggle" name="user_action" value="remove_lastviewed" data-value="add_lastviewed" /> <?php } else { ?> <a href="#" title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" data-title="<?php _e('Remove from Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button"></a> <input type="hidden" class="toggle" name="user_action" value="add_lastviewed" data-value="remove_lastviewed" /> <?php } ?> <input type="hidden" name="user_lastviewed" value="<?php echo ThemexUser::$data['active_user']['ID']; ?>" /> <input type="hidden" class="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" /> <input type="hidden" class="action" value="<?php echo THEMEX_PREFIX; ?>update_user" /> </form> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { window.setInterval(function() { AutoPost(); }, 3000); }); function AutoPost() { $.ajax({ type: "POST", url: "<?php echo AJAX_URL; ?>", data: $('#lastviewer').serialize() success: function(data) { $("#lastviewer").html(data) ; } }); } </script>
  4. Hi, Thank you for the quick response but it still didn't submit anything. Im a real novice so apologies in advance. thank you
  5. Hi, I have the below code and jquery in wordpress. I would like the form to auto submit, but at the moment I just get a 0 in the place of the heart icon. it seems to refresh but the form is not submitting the query. Thank you in advance <form id="lastviewer" class="ajax-form" action="<?php echo AJAX_URL; ?>" method="POST"> <?php if(ThemexUser::islastviewed(ThemexUser::$data['active_user']['ID'])) { ?> <a href="#" title="<?php _e('Remove from lastviewed', 'lovestory'); ?>" data-title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button current"></a> <input type="hidden" class="toggle" name="user_action" value="remove_lastviewed" data-value="add_lastviewed" /> <?php } else { ?> <a href="#" title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" data-title="<?php _e('Remove from Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button"></a> <input type="hidden" class="toggle" name="user_action" value="add_lastviewed" data-value="remove_lastviewed" /> <?php } ?> <input type="hidden" name="user_lastviewed" value="<?php echo ThemexUser::$data['active_user']['ID']; ?>" /> <input type="hidden" class="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" /> <input type="hidden" class="action" value="<?php echo THEMEX_PREFIX; ?>update_user" /> </form> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { window.setInterval(function() { AutoPost(); }, 3000); }); function AutoPost() { $.ajax({ type: "POST", url: "<?php echo AJAX_URL; ?>", success: function(data) { $("#lastviewer").html(data) ; } }); } </script>
  6. Hi, I'm a novice and have the below code in a Wordpress theme. I'm trying to get the form to submit automatically so it logs an entry into the MySql db as though the person clicked the heart icon (submit). Ideally I subsequently want to hide the heart icon so on load maybe after 3 seconds the entry is auto fired to the MySql DB. I have got as far as the manual click adding the entry, however can't get to to auto submit, any gel would be appreciated. Thank you in advance. ////PHP Form///// <form class="ajax-form" action="<?php echo AJAX_URL; ?>" method="POST"> <?php if(ThemexUser::islastviewed(ThemexUser::$data['active_user']['ID'])) { ?> <a href="#" title="<?php _e('Remove from lastviewed', 'lovestory'); ?>" data-title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button current"></a> <input type="hidden" class="toggle" name="user_action" value="remove_lastviewed" data-value="add_lastviewed" /> <?php } else { ?> <a href="#" title="<?php _e('Add to Last Viewed', 'lovestory'); ?>" data-title="<?php _e('Remove from Last Viewed', 'lovestory'); ?>" class="icon-heart submit-button"></a> <input type="hidden" class="toggle" name="user_action" value="add_lastviewed" data-value="remove_lastviewed" /> <?php } ?> <input type="hidden" name="user_lastviewed" value="<?php echo ThemexUser::$data['active_user']['ID']; ?>" /> <input type="hidden" class="nonce" value="<?php echo wp_create_nonce(THEMEX_PREFIX.'nonce'); ?>" /> <input type="hidden" class="action" value="<?php echo THEMEX_PREFIX; ?>update_user" /> </form> ////Ajax///// //Elements var themeElements = { ajaxForm: '.ajax-form', } //AJAX Form $(themeElements.ajaxForm).each(function() { var form=$(this); form.submit(function() { var message=form.find('.message'), loader=form.find('.loader'), toggle=form.find('.toggle'), button=form.find(themeElements.submitButton), title=form.find(themeElements.submitButton).data('title'); var data={ action: form.find('.action').val(), nonce: form.find('.nonce').val(), data: form.serialize() } loader.show(); button.addClass('disabled').toggleClass('current'); if(!message.hasClass('static')) { message.slideUp(300, function() { $(themeElements.colorboxLink).colorbox.resize(); }); } jQuery.post(form.attr('action'), data, function(response) { if(jQuery('.redirect', response).length) { if(jQuery('.redirect', response).attr('href')) { window.location.href=jQuery('.redirect',response).attr('href'); } else { window.location.reload(); } message.remove(); } if(title) { button.data('title', button.attr('title')); button.attr('title', title); } toggle.each(function() { var value=toggle.val(); toggle.val(toggle.data('value')); toggle.data('value', value); }); loader.hide(); button.removeClass('disabled'); if(response!='' && response!='0' && response!='-1') { if(message.hasClass('popup')) { $.colorbox({html:'<div class="popup">'+response+'</div>'}); } else if(message.hasClass('static')) { message.append(response); } else { message.html(response).slideDown(300, function() { $(themeElements.colorboxLink).colorbox.resize(); }); } } form.find('.temporary').val(''); form.find('.scroll').each(function() { $(this).scrollTop($(this)[0].scrollHeight); }); }); return false; }); }); Thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.