jeudi 22 janvier 2015

Run javascript function after login if checkbox is selected

I am making a Wordpress site where users can vote on posts if the are loggedin, this is currently working. What I want to do now, is to give them the option to place their votes by selecting a checkbox before they have loggedin on the site. If the checkbox is not selected the function must run as it does now. I hope I was clear in my explanation. Thank you in advance.


This is the form that runs the script below if the users are loggedin. And have not already voted by selecting the checkbox in the form at the bottom, before loggin in.



<textarea id="msg" maxlength="100" rows="4" class="widget_textarea"></textarea>
<button type="submit" class="vote widget_button">Sign</button>
<input type="hidden" id="post_id" value="<?php the_ID() ?>">


The script than users can run with the form above if they are loggedin. Should also run if users selected the checkbox in the from below, before logging in.



$(".vote").click(function() {
$(".vote").html('busy');
$url = "/vote/?petitie_id=" + $("#post_id").val() + "&msg=" + $("#msg").val();

$.ajax({
dataType: "json",
url: $url
})
.done(function(data) {
$(".vote").html('done');
if (data.success) {

$(".vote").html('voted')

} else {
$(".vote").html('already voted');

}
})
.fail(function() {
alert('fail');
})
});


The login form with checkbox, this has to run the script above after login if the checkbox was selected.



<form name="loginform" class="wpuf-login-form row" id="loginform" action="/login/" method="post">
<div class="col-md-12 col-sm-12 col-xs-12 login_section_login_forms">
<div class="form-group">
<input type="text" name="log" class="form-control top-buffer" placeholder="Naam" value="" size="20" />
</div>
<div class="form-group">
<input type="password" name="pwd" class="form-control top-buffer" placeholder="Wachtwoord" value="" size="20" />
</div>
<input id="vote_for_me" type="checkbox"> Login and vote<br>
<?php do_action('login_form'); ?>
</div>
<div class="col-md-12 col-sm-12 col-xs-12 login_button">
<input type="submit" name="wp-submit" type="button" id="myButton1" class="btn btn-danger btn-lg btn-block" value="<?php esc_attr_e('Log In'); ?>" />
<input type="hidden" name="redirect_to" value="<?php echo WPUF_Login::get_posted_value('redirect_to'); ?>" />
<input type="hidden" name="wpuf_login" value="true" />
<input type="hidden" name="action" value="login" />
<?php wp_nonce_field('wpuf_login_action'); ?>
</div>
</form>




Aucun commentaire:

Enregistrer un commentaire