E
E
Evgeny Shevtsov2015-02-16 14:02:18
JavaScript
Evgeny Shevtsov, 2015-02-16 14:02:18

How to rewrite the script to work with three forms?

There is a script.
works with two forms... I just can't rewrite it to work with three forms...

jQuery(document).ready(function ($) {
    // Display form from link inside a popup
  $('#pop_login, #pop_signup').live('click', function (e) {
        formToFadeOut = $('form#register');
        formtoFadeIn = $('form#login');
        if ($(this).attr('id') == 'pop_signup') {
      formToFadeOut = $('form#login');
            formtoFadeIn = $('form#register');
      
        }

  
        formToFadeOut.fadeOut(500, function () {
            formtoFadeIn.fadeIn();
        })
    
        return false;
    });


    // Show the login/signup popup on click
    $('#show_login, #show_signup).on('click', function (e) {
        $('body').prepend('<div class="login_overlay"></div>');
        if ($(this).attr('id') == 'show_login') 
      $('form#login').fadeIn(500);
        else
      $('form#recover').fadeIn(500);
    
        e.preventDefault();
    });

  // Perform AJAX login/register on form submit
  $('form#login, form#register').on('submit', function (e) {
        if (!$(this).valid()) return false;
        $('p.status', this).show().text(ajax_auth_object.loadingmessage);
    action = 'ajaxlogin';
    username = 	$('form#login #username').val();
    password = $('form#login #password').val();
    email = '';
    security = $('form#login #security').val();
    if ($(this).attr('id') == 'register') {
      action = 'ajaxregister';
      username = $('#signonname').val();
        	email = $('#email').val();
        	security = $('#signonsecurity').val();	
    }
    
    ctrl = $(this);
    $.ajax({
            type: 'POST',
            dataType: 'json',
            url: ajax_auth_object.ajaxurl,
            data: {
                'action': action,
                'username': username,
                'password': password,
        'email': email,
                'security': security
            },
            success: function (data) {
        $('p.status', ctrl).text(data.message);
        if (data.loggedin == true) {
                    document.location.href = ajax_auth_object.redirecturl;
                }
            }
        });
        e.preventDefault();
    });
  
  // Client side form validation
    if (jQuery("#register").length) 
    jQuery("#register").validate();
    else if (jQuery("#login").length) 
    jQuery("#login").validate();
});

Who will tell you how to do it? *)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly Bobrov, 2015-02-18
@bobrov1989

pass the form selector inside the handler, pass requests with data objects to Ajax.
P.S. live method - depricated - can be used instead of .live('click' and .on('click' - .click()

A
Artem @Jump, 2017-10-19
@Emiljen

The power of the charger is not enough under heavy load, the voltage drops below what is necessary for charging.

M
murzik_a, 2017-10-18
@murzik_a

Home charger? It may not have enough power under load.

K
kalapanga, 2017-10-18
@kalapanga

There is a simple option - broken power connector. Or what they stick in, or what they stick into. According to the description, it is very similar!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question