Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="vb-registration-form">
- <form data-abide novalidate id="reg-form" class="registration-form">
- <!-- The form goes here. I have removed it from this post to avoid making the question too long. -->
- <div class="g-recaptcha" data-sitekey="my_sitekey_is_entered_here"></div>
- <fieldset class="large-6 columns">
- <button class="button" type="submit" id="btn-new-user" value="Submit" display="none">Submit</button>
- </fieldset>
- <fieldset class="large-6 columns">
- <button class="button" type="reset" value="Reset">Reset</button>
- </fieldset>
- </div>
- </div> <!-- close vb-reg form -->
- </form>
- <div class="row">
- <div class="medium-12 columns" id="successfulregistration" style="display:none">
- <div class="callout success">
- <h2>Thank you for registering.</h2>
- <p>Please look for an email from us confirming your registration. We will confirm your account within 3-5 business days.</p>
- </div>
- </div>
- <div class="medium-12 columns" id="unsuccessfulregistration" style="display:none;" >
- <div class="callout alert">
- <h2>There was a problem...</h2>
- <p class="responsemsg"></p>
- </div>
- </div>
- </div>
- jQuery( document ).ready( function( $ ) {
- var form = document.getElementById('reg-form');
- /*** When user clicks on button... ***/
- $('#btn-new-user').click( function(event) {
- var elements = this.elements;
- /*** Prevent default action, so when user clicks button he doesn't navigate away from page**/
- if (event.preventDefault) {
- event.preventDefault();
- } else {
- event.returnValue = false;
- }
- // Collect data from inputs
- var reg_nonce = $('#vb_new_user_nonce').val();
- var reg_user = $('#vb_username').val();
- var reg_pass = $('#vb_pass').val();
- var reg_mail = $('#vb_email').val();
- var first_name = $('#vb_FirstName').val();
- var last_name = $('#vb_LastName').val();
- var inst_affil = $('#vb_institutionalaffiliation').val();
- var location = $('#vb_location').val();
- var twitter = $('#vb_twitter').val();
- var bio = $('#vb_bio').val();
- var captcha_response = $('#g-recaptcha-response').val();
- var checkboxValues = [];
- $('input[name=signup]:checked').map(function() {
- checkboxValues.push($(this).val());
- });
- console.log(checkboxValues);
- /**
- * AJAX URL where to send data
- * (from localize_script)
- */
- var ajax_url = vb_reg_vars.vb_ajax_url;
- // Data to send. The register_user action corresponds to the action in functions.php
- data = {
- action: 'register_user',
- nonce: reg_nonce,
- user: reg_user,
- pass: reg_pass,
- mail: reg_mail,
- firstname: first_name,
- lastname: last_name,
- institution: inst_affil,
- location: location,
- twitterhandle: twitter,
- userbio: bio,
- volunteerdates: checkboxValues,
- captcha: captcha_response
- };
- console.log(data);
- console.log(data.user);
- // Do AJAX request
- $.post( ajax_url, data, function(response) {
- // If we have response
- if( response ) {
- if( response === '1' ) {
- // If user is created
- $('.vb-registration-form').remove();
- $('#successfulregistration').show();
- console.log(response);
- } else {
- $('.vb-registration-form').remove();
- $('#unsuccessfulregistration').show();
- $('.responsemsg').append(response);
- console.log(response);
- }
- }
- });
- });
- });
- function vb_reg_new_user() {
- $privatekey = 'private_key_is_entered_here'
- $args = array(
- 'body' => array(
- 'secret' => $privatekey,
- 'response' => stripslashes( esc_html ($_POST["captcha_response"] ) )
- ));
- $resp = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', $args);
- $response = json_decode( wp_remote_retrieve_body( $response ), true);
- // Verify nonce
- if( !isset( $_POST['nonce'] ) || !wp_verify_nonce( $_POST['nonce'], 'vb_new_user' ) ) {
- die( 'Ooops, something went wrong, please try again later.' );
- } elseif ( $response != 'True'){
- die( 'Captcha error');
- } else {
- // Post values
- $username = $_POST['user'];
- $password = $_POST['pass'];
- $email = $_POST['mail'];
- $fname = $_POST['firstname'];
- $lname = $_POST['lastname'];
- $instaffil = $_POST['institution'];
- $loc = $_POST['location'];
- $twitter = $_POST['twitterhandle'];
- $bio = $_POST['userbio'];
- $voldates = $_POST['volunteerdates'];
- $username = sanitize_text_field($username);
- $fname = sanitize_text_field($fname);
- $lname = sanitize_text_field($lname);
- $instaffil = sanitize_text_field($instaffil);
- $loc = sanitize_text_field($loc);
- $twitter = sanitize_text_field($twitter);
- $bio = sanitize_text_field($bio);
- $userdata = array(
- 'user_login' => $username,
- 'user_pass' => $password,
- 'user_email' => $email,
- 'first_name' => $fname,
- 'last_name' => $lname,
- 'description' => $bio,
- 'role' => 'pending'
- );
- $user_id = wp_insert_user( $userdata ) ;
- // Return
- if( !is_wp_error($user_id) ) {
- echo '1';
- echo $response['success'];
- notifyadmin($email, $username, $fname, $lname);
- notifyuser($email, $fname, $lname);
- } else {
- echo $user_id->get_error_message();
- echo $response['success'];
- }
- add_user_signupmeta($user_id, $voldates);
- die();
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement