Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

MultipleFields to databse

Go to End

3 Posts   795 Views


Community Member, 99 Posts

18 August 2012 at 2:46am

I have an online form where the user is able add multiple delegates

eg: name,email ..etc
and you click add to add another input box

so for example the form would end up with this on submission for 4 delegates
<!-- delegate One -->
< input type="text" class="text rounded" id="Form_EventBookingForm_DelFirstName" name="DelFirstName" value="" />
< input type="text" class="text rounded" id="Form_EventBookingForm_DelLasttName" name="DelLastName" value="" />

<!-- delegate Two -->
< input type="text" class="text rounded" id="Form_EventBookingForm_DelFirstName_0" name="DelFirstName_0" value="" />
< input type="text" class="text rounded" id="Form_EventBookingForm_DelLasttName_0" name="DelLastName_0" value="" />

<!-- delegate Three -->
< input type="text" class="text rounded" id="Form_EventBookingForm_DelFirstName_1" name="DelFirstName_1" value="" />
< input type="text" class="text rounded" id="Form_EventBookingForm_DelLasttName_1" name="DelLastName_1" value="" />

<!-- delegate Four -->
< input type="text" class="text rounded" id="Form_EventBookingForm_DelFirstName_2" name="DelFirstName_2" value="" />
< input type="text" class="text rounded" id="Form_EventBookingForm_DelLasttName_2" name="DelLastName_2" value="" />

How can i collect this and save for each () one to the database.
I know how to get i entry saved.

//save the Delegate(s)
$delegates = New Delegates();
$fields = array(
$form->saveInto($delegates, $fields);


Forum Moderator, 1899 Posts

18 August 2012 at 4:02am

I do this and I use the same logic to create the form as to save it...

1. when building your form there is a loop right? and you use that to add the "_X" for the delegates?


for($i=0; $i<$iNumDelegates;$i++) {
	$fields->push(new TextField('DelFirstName_'.$i))
	//repeat for each field
	//I use another loop on the getFrontEndFields method of the required object

2. when you save go through the same loop like you are making the fields and then instead save them into a new object

for($i=0; $i<$iNumDelegates;$i++) {
	$delegate = new Delegate();
	//repeat for each field

Hope this helps!


Community Member, 99 Posts

22 August 2012 at 3:11am

Yes this really helped me
many thanks

	$NumDelegates = $data['DelegateCount'];
				$iNumDelegates = ($data['DelegateCount'] - 1);
		if ($NumDelegates > 1) {
		$iNumDelegates = ($data['DelegateCount'] - 1);
			for($i=0; $i<$iNumDelegates;$i++) {
			   $delegate = new Delegates();
			   //repeat for each field