Friday, September 30, 2011

Re: Can't get my form in a modal box working in cakephp

Sarah,

It appears you have not yet got your head around what AJAX calls are
and how they are relevant to what you are doing. Normally when you
click on a link within a web page it sends a request to the link's
address, does something on the server/database, and loads a new page
with whatever data that request returns.

With JavaScript and AJAX you send a request to the server without
reloading your page, 9 times out of 10 that request will do something
in the database (activate/deactiveate/delete a record) and return some
data which you then insert into the current page's DOM using
javascript. This is what you're trying to achieve and mine and Sam's
posts have been trying to guide you in the right direction.

You need to submit the form within your modal using AJAX. Adding
class='nyroModal' to the form tag allows the nyroModal plugin to
override the forms default behaviour of submitting the form and
reloading the page, and instead will serialize (a javascript function
which gets all the form data in a format that can be sent via AJAX)
the form's values and then submit it via AJAX to your forms method
paramter value (i.e. /images/upload)

Your first goal should be to ensure this is happening by installing
FIreBug and watching the console tab when submitting the form. Here
you will see if there was an AJAX request fired, what it sent to the
server, and what the server returned.

Once you get that working you need to make sure your controller action
is able to properly deal with the data being sent, do it's things and
then return the relavant data. Some things you need to check for:

1. Is the form data available in $this->data, if not check $this-
>params to see if it is in the form array instead

2. What layout are you using when returning data, this is why we told
you to apply RequestHandler and use:

if($this->RequestHandler->isAjax()) {
$this->layout = 'ajax';
// any other specific logic for your ajax calls
}

This tells cake not to use your default layout which includes all the
tags required for loading an entire page, all you want to return is a
HTML snippet or some JSON.

3. What format do you need to return your data in? This then comes
back to NyroModal as that is what sent the AJAX request and should
handle the returned data. From my quick look at the documentation I
did not see anything that detailed how to achieve this so you would
have to experiment yourself with what format the data is returned in
and how you then access and insert that data into your modal.

The moral of all of this is you really do need to understand at least
the fundamentals of how the varous plugins your adding to your
application work, otherwise when things go wrong you have not got a
clue what to do next.

The other thing that may throw up complications with this one is your
coupling your problems of sending data via a modal form with using
MilesJ's Uploader script. Maybe it's worthwhile contacting Miles and
asking him what he would use to achieve what your attempting.

HTH, Paul

On Sep 29, 2:13 pm, Sam Sherlock <sam.sherl...@gmail.com> wrote:
> Are you using firebug or such?
>
> Or place some calls to $this->log in the given controller action.
>
> - S
> On 29 Sep 2011 13:55, "crazysarahtemple...@aol.com" <
>
>
>
>
>
>
>
> crazysarahtemple...@aol.com> wrote:
> > Hey there. I've added
> > var $components = array('RequestHandler');
> > to my Images_Controller
>
> > and
> > if ($this->RequestHandler->isAjax())
> > to the function that the form is meant to submit to but that did
> > absolutely nothing at all :(
>
> > Any further hints?
>
> > thanks
>
> > --
> > Our newest site for the community: CakePHP Video Tutorials
>
> http://tv.cakephp.org> Check out the new CakePHP Questions sitehttp://ask.cakephp.organd help
>
> others with their CakePHP related questions.
>
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group
>
> athttp://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: