Re: AJAX form submission with jQuery

2007-11-25 Thread Sergei

Of course error messages wont appear, because form html needs to be
updated somehow. Just do javascript validation in your case.


On Nov 25, 10:40 pm, Action <[EMAIL PROTECTED]> wrote:
> I'm kind of at a loss why posting the form data using ajax to the
> controller method is resulting in it not showing validation error
> messages. How do I use the model's validation when submitting the form
> using ajax in jquery? The validation works (it won't submit invalid
> data), but the error messages never appear (they do appear when
> submitted not using ajax).

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: AJAX form submission with jQuery

2007-11-25 Thread Action

I'm kind of at a loss why posting the form data using ajax to the
controller method is resulting in it not showing validation error
messages. How do I use the model's validation when submitting the form
using ajax in jquery? The validation works (it won't submit invalid
data), but the error messages never appear (they do appear when
submitted not using ajax).

On Nov 15, 7:46 pm, bunyan <[EMAIL PROTECTED]> wrote:
> I did it the following way:
>
> An action returns the rendered view if there were errors while saving
> the data, otherwise it returns xml that contains info including what
> page element should be refreshed etc.
>
> JS code:
>
> # make form "ajax"
>
> var makeAjaxForm = function(){
> $('form',this).ajaxForm({
> //onActionSubmit will be fired when the response
> is received
> success: onActionSubmit
> });
> };
>
> #reloads form on error or sends response xml to processing
>
> var onActionSubmit = function(responseText) {
> //if the response is xml
> if(jQuery.isXMLDoc(responseText)) {
> //process it, reload some elements etc
> processXML(responseText);
>
> //hide form
> hideActionBox();
> } else {
> //load the rendered view into #reqAction .content (the
> form container)
> $('#reqAction .content').html(responseText);
> //make the form ajax again
> makeAjaxForm();
> }
> };
>
> Action wrote:
> > I have a blog-like page that contains a post, comments, and a new
> > comment form. I want the new comment form to submit using ajax (but
> > also work if the user has js disabled) and have the newly added
> > comment appear in the comments list.
>
> > Currently, I'm using thejQueryForm Plugin to submit the form:
> >http://www.malsup.com/jquery/form/. I don't want to use the prototype
> > helper due to the inline code it generates.
>
> > So far, the form submission works, but all that is happening is the
> > data being saved. The view does not show any validation error messages
> > defined in the model and does not show the new comment (I have to
> > refresh the page to get the
>
>  comment to show up and the validation
>
> > error messages never show up).
>
> > How can I fix this so the form not only submits using ajax, but the
> > form data is also rendered in the view if saved, or the appropriate
> > validation error messages appear? I've done some searching and I think
> > I'm supposed to use the requestHandler component. However, I don't
> > really understand how I am supposed to use it in this situation (the
> > manual documentation is pretty vague).
>
> > Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: AJAX form submission with jQuery

2007-11-16 Thread Action

What do I have to change on the cake side of things to get this
working? Currently it's just set up for non-ajax submission, but I
figured submitting the data using ajax would yield the same results.

The form appears on posts/view and submits to comments/add, which
saves the form if it validates. If it invalidates, it stores the
validation info into a session and redirects back to posts/view where
the error messages are outputted (form helper).

Here's my current code:

posts/view:

function view($slug = NULL)
{
if($slug == NULL)
{
$this->redirect('/posts');
}
//Find post by slug.
$this->set('data', $this->Post->findBySlug($slug));
}

comments/add:

function add()
{
if (!empty($this->data))
{
if ($this->Comment->save($this->data))
{
$this->Session->setFlash('The Comment has been
saved', $layout = 'flash_success');
}
else
{
$this->_persistValidation('Comment');
$this->Session->setFlash('The Comment could not be
saved. Please correct the errors and try again.', $layout =
'flash_error');
}
}
$this->redirect($this->referer(), null, true);
}
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: AJAX form submission with jQuery

2007-11-15 Thread bunyan

I did it the following way:

An action returns the rendered view if there were errors while saving
the data, otherwise it returns xml that contains info including what
page element should be refreshed etc.

JS code:

# make form "ajax"

var makeAjaxForm = function(){
$('form',this).ajaxForm({
//onActionSubmit will be fired when the response
is received
success: onActionSubmit
});
};

#reloads form on error or sends response xml to processing

var onActionSubmit = function(responseText) {
//if the response is xml
if(jQuery.isXMLDoc(responseText)) {
//process it, reload some elements etc
processXML(responseText);

//hide form
hideActionBox();
} else {
//load the rendered view into #reqAction .content (the
form container)
$('#reqAction .content').html(responseText);
//make the form ajax again
makeAjaxForm();
}
};

Action wrote:
> I have a blog-like page that contains a post, comments, and a new
> comment form. I want the new comment form to submit using ajax (but
> also work if the user has js disabled) and have the newly added
> comment appear in the comments list.
>
> Currently, I'm using the jQuery Form Plugin to submit the form:
> http://www.malsup.com/jquery/form/. I don't want to use the prototype
> helper due to the inline code it generates.
>
> So far, the form submission works, but all that is happening is the
> data being saved. The view does not show any validation error messages
> defined in the model and does not show the new comment (I have to
> refresh the page to get the
 comment to show up and the validation
> error messages never show up).
>
> How can I fix this so the form not only submits using ajax, but the
> form data is also rendered in the view if saved, or the appropriate
> validation error messages appear? I've done some searching and I think
> I'm supposed to use the requestHandler component. However, I don't
> really understand how I am supposed to use it in this situation (the
> manual documentation is pretty vague).
>
> Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---