Hi Mark I'd try it a more cakey way.
Your model would have the following relationship Registration HasAndBelongsToMany AudienceType id, name AudienceType being your data > array(1 => '5-7 years', 2 => '7-11 years', '3 => '7-11 years'); You'd store the relationship between the two in a join table so you'd have a table with the following fields registration_id, audience_type_id That would allow you to look up registrations via the audience_type_id My feeling is this is a better way for you to link this Read more in the book http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html HTH. Mike On 17 Sep 2014, at 11:01, MarkB <[email protected]> wrote: > Hi, > > I'm new to CakePHP, OOP and my PHP knowledge & skills could probably be > considered beginner++ level, so please have patience with me. > > I'm producing an event registration system for a festival website. I have > created a multi-step form that uses a session to temporarily record data. It > asks users to specify the ideal audience for their event, based upon age. > This needs to allow multiple selections, and I want to collate and write > their selections into a single mySQL database text field called 'audience'. > > The code I'm using to create the multiple selections in my form view is as > follows (actual form has several more options) > > $options = array('5-7' => '5-7 years', '7-11' => '7-11 years', '11-14' => > '7-11 years'); > echo $this->Form->select('audience', $options, array('multiple' => > 'checkbox')); > > This generates the following HTML: > > <input type="hidden" name="data[Proposal][audience]" value="" > id="ProposalAudience"/> > <div class="checkbox"><input type="checkbox" > name="data[Proposal][audience][]" value="5-7" id="ProposalAudience57" > /><label for="ProposalAudience57">5-7 years</label></div> > <div class="checkbox"><input type="checkbox" > name="data[Proposal][audience][]" value="7-11" id="ProposalAudience711" > /><label for="ProposalAudience711">7-11 years</label></div> > <div class="checkbox"><input type="checkbox" > name="data[Proposal][audience][]" value="11-14" id="ProposalAudience1114" > /><label for="ProposalAudience1114">11-14 years</label></div> > > The code I'm using in my controller file to write to the database is as > follows: > > $arrAudience = $this->Session->read('form.data.audience'); > $strAudience = implode($arrAudience); > $this->Session->write('form.data.audience', $strAudience); > $this->Proposal->save($currentSessionData); > > But I get the following errors: > > Warning (2): implode() [function.implode]: Argument must be an array > [APP/Controller/ProposalsController.php, line 106] > Notice (8): Array to string conversion > [CORE/Cake/Model/Datasource/DboSource.php, line 1009] > > The SQL query dump has the word 'Array' where I'd expect my string to be. > > Where am I going wrong? Should I be using something other than the basic PHP > implode function? > > Thanks for any help you can give. > > > > > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. .................................... Mike Karthäuser Director, Brightstorm Ltd. 1, Brewery Court North Street Bristol BS3 1JS [email protected] www.brightstorm.co.uk +44(0) 7939252144 .................................... -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
