Thanks for your response. I did take a look at your tutorial. But in my situation I don't think a lot of what you have there will apply to me. I have everything to a point working. Right now I am only trying to validate one field using validate: remote option to check if a user email is already registered.
The data[User][email] = [email protected] gets sent to Cake . If I debug error I see Array ( [email] => This email account is already registered. ) I just need a way to get the error or success back to the js remote part of the script...thats where I am lost. I am not sure how to send back the message if there is an error or if valid do nothing. I tried using your suggestion with layout ajax but all I ended up getting was an error messages showing {valid : false} where "This email account is already registered." Should go. My js validate rule looks like: var validate_profile = { rules: { 'data[Profile][email]':{required: true, email:true, remote: {url: "/manage/profiles/validate",type: "post"}}, }, messages: { 'data[Profile][email]': { required: '* JS required email address.', email: '* JS email address.', remote: '* this message is remote from JS.'} }}; And my controller: function manage_validate() { Configure::write('debug', 2); if ($this->RequestHandler->isAjax()) { $this->Profile->set($this->data); if ($this->Profile->validates()) { //nothing to do } else { //header("Content-type: text/plain"); $errors = $this->Profile->invalidFields(); //debug($errors); $array = array("valid" => false); return json_encode($array); //$this->set('output' , $output); //echo json_encode($array); //$this->layout = 'ajax'; //$this->render ('/elements/errors/ajax_fields'); } } } Ajax_fields.ctp : <?php echo $javascript->object($output);?> Any ideas? Thanks again Dave -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Kyo Sent: November-06-09 10:43 PM To: CakePHP Subject: Re: Help returning JSON You don't have to use header() and json_encode() to get JSON values back with Cake. Use $this->layout = 'ajax' in your controller and $javascript->object () in your view. Try out my way: http://jamnite.blogspot.com/2009/05/cakephp-form-validation-with-ajax-using. html hth, Kyo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
