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

    I would like to use registration with LOGIN add-on with an ajax request.
    but after many test nothing seems to work.
    can you help me ?

    my ajax script:

    
    var core={
    ajax:function(param,callback){
    		$.ajax({
    			url: 'ajax/',type: 'POST',dataType: 'json',data: param,
    			beforeSend: function(data){core.loading.start();},
    			success: function(data){ console.log('success'); callback.call(this,data);},
    			error:function(jqXHR, textStatus, errorThrown){ console.log(errorThrown); console.log(textStatus); },
    			complete: function(data){core.loading.close();}
    		});
    }
    
    var form=$('#registerform').serializeJSON();
    					var data = {'action':'register','component':'login','form':form};
    					core.ajax(data,register.callback);
    
    


    my ajax page

    <?php
    $sanitizedRequests = $modx->sanitize($_REQUEST); // recommended, will be applied to all $_GET, $_POST, $_COOKIE
    $_REQUEST = array();
    $_REQUEST = $sanitizedRequests;
    $output='';
    
    //this is the processor file name
    $procname=$_REQUEST['action'];
    
    //this is what component we are referencing
    $comp=$_REQUEST['component'];
    
    //get the processor file with path
    $f= $modx->getOption('core_path').'components/'.$comp.'/processors/'.$procname.'.php';
    if (file_exists($f)) {
    	//include that file so the output of the processor is assigned here
    	$output= include $f;
    } else {
    	$output= 'Action not found: '.$f;
    }
    //convert the processor output to json format
    return $modx->toJSON($output);
    
    


    thanks for your help

      • 32699 ☆ A M B ☆
      • 427 Posts
      I played with this some time ago. I believe you are way over thinking it, but the issue is the user's $_SESSION. You will find that a page reload may be required to get the cookie on the browser to sync with the site.

      In any case, I believe all requests are sanitized already via the modRequest class.

      Just capture the content in a form and send it to a page with the correct Snippet in it, but be very careful. Shaun has gone to lengths to make sure your site isn't compromised through the login script, and there are some very helpful functions in his Package to help protect you from abuse.

      var form=$('#registerform').serializeJSON();


      You are switching the form to JSON. Does his Package even support JSON as a valid input or is it looking for a PHP Array? Do you to need to do a fromJSON in a Catcher Snippet to hand off to his Register Snippet?

        Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

        Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com