We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39928
    • 7 Posts
    Hi Everyone,

    I'm very new to this but i got my way around ModX Revo so far as to implement the Login Add-On smiley and customizing my pages into ModX. However, I'd like to really know how to add some jquery/ajax capabilities to modx login. The idea is basically have the login form not refresh on every submit validation / redirct to member page process. Error message does show successfully but i'd like it to show on the form without refresh.

    I've read a couple of forums lately and wasn't successfully in implementing its concept to Login. If there's a particular place i can start looking into, greatly appreciate the direction to it.

    i'd like to know if such implementation is supported for Login ModX?
    Is there a key process i can look into for ajax to pull validating proccess and sending them back to login form?


    Thanks,
    Ken
      • 3749
      • 24,544 Posts
      It doesn't need to be integrated with Login or the form. JavaScript validation is performed on the client side and intercepts the user's input before the form is submitted.

      Take a look at the SPForm code for an example. It has built-in JS validation. The code is in core/components/spform/classes/spform.class.php around line 80.


      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 39928
        • 7 Posts
        Hi Bob,

        Thanks for getting back. Hope your patience to this will bring fruits to a novice like me.

        I'm using MODX Revolution 2.1.5-pl (traditional)
        WebServer :Apache 2.2.12 (IPV6 Enabled)
        DBase : MYSQL 5.1.37
        PHP 5.3.0

        I get the concept of not having to integrate it with the form but what i'm trying to get at is particularly the ModX Login Add-On which has some sort of validating process on php which i need to output back on the [[+error]] placement without refreshing the page. And if validated, then it should redirect to the membership chunk using personalize snippet.

        My login form looks like as attached. (log01.jpg) The login form works but when an error happens like invalid user, i will have to click on the "Sign in" button to see the error message as the form happens to refresh everytime on submit.

        My lgnLoginTpl looks like this below
        								<fieldset id="signin_menu">
        <div class="loginMessage" id="msg">[[+errors]]</div>
        <div id="contact_form">  
        	<form class="loginLoginForm" method="post" name="contact" id="signin" action="">
        										<p>									
        											<label for="username">[[%login.username]]
        											<input id="username" class="loginUsername" type="text" name="username" tabindex="4" />
        											</label>
        										</p>
        										<p>
        											<label for="password">[[%login.password]]
        											<input id="password" class="loginPassword" type="password" name="password" tabindex="5" />
        											</label>
        											<input class="returnUrl" type="hidden" name="returnUrl" value="[[+request_uri]]" />
        										</p>
        										<p class="remember">
        											<input type="button" id="login" value="[[+actionMsg]]" />
        											<input id="remember" name="remember_me" value="1" tabindex="7" type="checkbox">
        											<label for="remember">Remember me</label>
        											[[+login.recaptcha_html]]			
        
        											<input class="loginLoginValue" type="hidden" name="service" value="login" />
        											
        										</p>
        										<p class="forgot-username"> 
        											<a id=forgot_username_link title="If you remember your password, try logging in with your email" href="[[~12]]">Forgot your username?</a><br>
        											<a id=forgot_username_link title="Apply for Membership" href="[[~15]]">Apply for Membership</a><br>											
        										</p>
        									</form>
        </div>									
        								</fieldset>
        


        And the <head> script on top uses the ajax trigger below.
           $("#username").keyup(function(e){
        		if(e.keyCode == 13){
                                var value = $("#username").val();
                                var datastr = "p_text="+value;
        			$.ajax({
        			type:'POST',
        			url:'[[~22]]',
        			data: $('signin'),
        			success:function(data){
        				$("#msg").html(data);
        			}
        		   });
        		}
        	});
        


        Resourceid 22 calls the [[!Login]] snippet which reflects the following code.
        require_once $modx->getOption('login.core_path',null,$modx->getOption('core_path').'components/login/').'model/login/login.class.php';
        $login = new Login($modx,$scriptProperties);
        if (!is_object($login) || !($login instanceof Login)) return '';
        
        $controller = $login->loadController('Login');
        $output = $controller->run($scriptProperties);
        return $output;
        


        I'm definitely wrong here as it's obviously not working and my ignorance is killing me on it. any sort of light will definitely help. Appreciate the community's response so far.
          • 3749
          • 24,544 Posts
          MODX can't check the username (which happens on the server side) until the form is actually submitted, which automatically refreshes the page, so I don't think what you're trying can work.

          I guess you could check the rest of the form in the JS, then do your own "secret" submit with cURL and interpret and display the results, but it would be a lot of work and I'm not sure it's worth it. The invalid username is a fairly rare occurrence.



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting