CakePHP: showing fail/success message under Ajax login form -


I use the AUTH component. I have a login form and I want to show a success / failure message without a page refreshes.

But when I submit a form ( jquery.form.js ):

  $ ('# login form'). Ajaxform (data) {alerts (data);});   

It returns home.ctp content in case of success and returns the HTML code of the login form in case of failure!

I have $ this-> AUTH- & gt; I want to get alert (data) in the login error .

These are some of the app_transfer beforeFilter settings:

  before the function filter () {$ this-> AUTH- & gt; LoginRedirect = false; $ This- & gt; AUTH- & gt; Logout redirect = false; $ This- & gt; AUTH- & gt; LoginError = __ ('Invalid e-mail or password.', True); $ This- & gt; AUTH- & gt; Auto redirect = false; $ This- & gt; Autorander = False; $ This- & gt; Presenting ('Login', 'Ajax'); }   

I used LogOnRed to render some arguments and to create an object for the jQuery process.

You can use the solution from blogpost .

Actually, this is a request from Ajax to differentiate it from an standard :

  $ This-> Request Handler-> IsAjax ()) / / If this is an Ajax call / / and other / if this is a standard action request / /   

and However, the debug level is set to 0 ( configure :: write ('debug', 0) ) and standard XHTML layout in / app / views / layouts / default. Ctp . Ajax layout for output data in standard .

Debug of submitted form looks like this:

  Configure :: Write ('debug', 0); $ This- & gt; Layout = 'Ajax'; If ($ this-> Request Handler-> is Ajax ()) {If (! ($ -> Data below!) {$ This-> Post- & gt; Create (); $ This- & gt; Later & gt; Set ($ this-> data ['post']); If ($ this- & gt; Post- & gt; Valid ()) {If ($ -> this-> Post-> Save ($ -> -> Data)) {$ message = __ ( 'Post has been saved.', True); $ Data = $ this- & gt; Data; $ This- & gt; Set ('success', compact ('message', 'data')); }} And {$ message = __ ('Post could not be saved. Please try again.', True); $ Post = $ this- & gt; Post- & gt; InvalidFields (); $ Data = compact ('post'); $ This- & gt; Set ('Errors', compact ('message', 'data')); }}   

and the subsequent output is done in JSON format:

  // error output {"errors": {"message": " The post could not be saved, please try again. "," Data ": {" post ": {" title ":" This field can not be left blank. "," Body ":" This field is not left blank Success "{{"} ": {" Message ":" Post has been saved. "," Data ": {" Post ": {" id ":" "," Title " : "Epsom Dollar Seat AMTiet", "Body": "Laurum Indies Dollar Seat A Mate, Ellicott ... "," Published ":" 1 "}}}}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -