1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 217 Views |
-
MultipleFields to databse

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 boxso 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(
'UniqueOrderID',
'DelegateTitle',
'DelFirstName',
'DelLastName',
'DelJobTitle',
'DelEmail',
'Dietary',
);
$form->saveInto($delegates, $fields);
$delegates->write(); -
Re: MultipleFields to databse

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?
e.g.
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();
$delegate->setField('DelFirstName','DelFirstName_'.$i)
//repeat for each field
$delegate->write();
}Hope this helps!
-
Re: MultipleFields to databse

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();
$delegate->setField('BookingEventID',$bookingeventid->ID);
$delegate->setField('BookeeUserID',$bookeeuser->ID);
$delegate->setField('DelFirstName',$data['DelFirstName_'.$i]);
$delegate->setField('DelLastName',$data['DelLastName_'.$i]);
$delegate->setField('DelEmail',$data['DelEmail_'.$i]);
$delegate->setField('DelJobTitle',$data['DelJobTitle_'.$i]);
$delegate->setField('DelDietary',$data['DelDietary_'.$i]);
//repeat for each field
$delegate->write();
}
}
[\code]
| 217 Views | ||
|
Page:
1
|
Go to Top |


