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 ( It returns I have These are some of the app_transfer 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 : and However, the debug level is set to 0 ( Debug of submitted form looks like this: and the subsequent output is done in JSON format: jquery.form.js ):
$ ('# login form'). Ajaxform (data) {alerts (data);});
home.ctp content in case of success and returns the HTML code of the login form in case of failure!
$ this-> AUTH- & gt; I want to get
alert (data) in the login error .
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'); }
$ This-> Request Handler-> IsAjax ()) / / If this is an Ajax call / / and other / if this is a standard action request / /
configure :: write ('debug', 0) ) and standard XHTML layout in
/ app / views / layouts / default. Ctp . Ajax layout for output data in standard .
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')); }}
// 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
Post a Comment