/**
* Process submitted AJAX data
*
* Checks if provided $data is valid, via {@link isValidPartial()}. If so,
* it returns JSON-encoded boolean true. If not, it returns JSON-encoded
* error messages (as returned by {@link getMessages()}).
*
* @param array $data
* @return string JSON-encoded boolean true or error messages
*/
public function processAjax(array $data)
{
require_once 'Zend/Json.php';
if ($this->isValidPartial($data)) {
return Zend_Json::encode(true);
}
$messages = $this->getMessages();
return Zend_Json::encode($messages);
}
On Fri, Apr 2, 2010 at 8:09 PM, Bill Chmura <Bill@explosivo.com> wrote:
>
> Okay, well the subject was a tough one to come up with so here is a better
> description:
>
> I have a Zend_Form... When you call the controller it renders the zend form
> on the page and gives it to you.
>
> You complete the zend form and JS packages it up and sends an Ajax request
>
> The ajax request takes the data, creates the form, and validates, etc that
> way and sends the data back
>
> Which then gets the data back and makes a pretty table.
>
> So my question is, how do I pass back the validation errors via the AJAX
> response?
>
> My thoughts currently are:
>
> 1) Screw the ajax, force a full page refresh each time
>
> 2) Render and pass the whole form back inside the response
>
> 3) Send back a validation error listing and parse it out in the client
>
>
> #2 seems easiest, but I feel strange about it for some reason.
>
> Anyone else tackle this before?
>
>
没有评论:
发表评论