I just ran into a situation today that required me to have access to more than one form field when doing an ajax request within my CakePHP application. Basically, when someone is typing an address, I want to check Google’s Geocode API for a latitude and longitude coordinate.
The important part is the ‘with’ option:
'with'=>'Form.serializeElements($("CommunityForm").getElements())'
My example:
echo $ajax->observeField('CommunityAddress', array('with'=>'Form.serializeElements( $("CommunityForm").getElements() )','url'=>'geocode','update'=>'geocode'"));
- The data being passed can be accessed in $this->params
- This solution requires the Prototype javascript library.
4 responses so far ↓
1 Suresh // Mar 14, 2008 at 9:28 am
Nice. it solve a big problem of me. Thanks buddy.
2 Sathyaprakash // Mar 21, 2008 at 7:12 am
Hi buddy,
I am new to cakephp. I am using the google map in my application. Can You explain me in details how to get the lattitude and longtitude when user entering the address.
And also please explain the use of the $ajax->observeField in detail.
Thanks in advance.
3 Tiago // Apr 1, 2008 at 12:14 pm
Thank you very much!
I was going nuts!!
4 Tamura // Oct 18, 2008 at 2:21 pm
Hi!
I’m trying to resolve a problem:
when i use $ajax->observeField in my view, the browser shows me a JS error (FireBug):
Form is not defined
[Break on this error] new Form.Element.EventObserver(’regionai…Headers:['X-Update', 'congregacoes']})})…
What can i do? Please, help me!
Leave a Comment