Ajax problem - need example

4 replies [Last post]
frostmar
Offline
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11

I'm looking to build a form with some general fields: Name, Address, Tel, etc. followed by a section called "Contacts in case of emergency". This would facilitate the entry of one or more contacts, again Name, address, phone etc. should the person become unwell. This would then be followed by other sections containing other fields relating to the original person.

Unfortunately, the video "Using the #ajax attribute for dynamic form building" only mentions this as a possibility with the briefest of instructions. In vain I looked at the example module provided by Drupal but this only allows for one field "Name" to be added. If I try and add more the order gets completely mashed up.

I searched through the code of CiviCRM as well but to no avail although they provide nice examples.

If anyone could point me in the direction of some sample code I would be grateful.

Thanks in advance.

Chris Shattuck
Offline
Last seen: 10 weeks 4 days ago
Joined: 2009-08-16
Hi Martin, I will be putting

Hi Martin,

I will be putting together some videos on this in the future, but in the meantime will keep my eyes out for a good code example to share. The code may be too involved to really follow well, but some of the field types allow for a "Add more" button and have multiple elements for each input. If you can pick through the code for this, you might find some inspiration.

Good luck, and I'll keep my eyes out!

Cheers,
Chris

frostmar
Offline
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11
New Videos

Hi Chris,

Any new videos yet covering this?

Martin.

Chris Shattuck
Offline
Last seen: 10 weeks 4 days ago
Joined: 2009-08-16
Hi Martin, I don't have

Hi Martin,

I don't have videos on this yet, but I do have some example code that might be helpful. The download at http://is.gd/beautifulforms, in the /sites/all/modules/custom folder contains an Ajax-looped example module, and a looped #state attribute example module that should give you what you need. The #state attribute one will be easier to implement and will be a bit snappier.

I hope this helps!
Chris

frostmar
Offline
Last seen: 6 years 29 weeks ago
Joined: 2011-06-11
Thank you

Thanks Chris,

There's some very useful stuff in that lot. I haven't got it solved yet but you've moved me along quite a bit!

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.