Hmm I already tried Model.id.field, but it doesn't work for me. I changed my view to so that it is generating html like so:
<div class="input select"><select name="data[UserAnswer][1][value]" id="UserAnswer1Value"> But instead of showing validation errors I get this error up the top of the page: Warning (2): preg_match() expects parameter 2 to be string, array given [CORE\cake\libs\validation.php, line 876] Maybe I need to try the latest SVN instead of RC3? Also my UserAnswer model doesn't have any belongs to relations, if that helps. Because the fix for https://trac.cakephp.org/ticket/4981 only seems to apply to belongs to relations. On Nov 8, 1:49 am, mark_story <[EMAIL PROTECTED]> wrote: > I closed your ticket, as I didn't have any troubles with using form > helper and saveAll(). Like teknoid said Model.1.field is the correct > format for multi record forms. I closed the ticket with additional > information. Perhaps this should be documented better? > > -Mark > > On Nov 6, 8:04 pm, Joel <[EMAIL PROTECTED]> wrote: > > > For reference I have created a ticket in trac > > here:https://trac.cakephp.org/ticket/5715 > > > On Nov 6, 5:23 pm, Joel <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > > I've run into a frustrating problem, I'm trying to validate an array > > > of the same type of model, but the > > > > I have used the name convention as suggested > > > here:http://manual.cakephp.org/complete/181/Core-Helpers#Field-naming-conv... > > > > eg: > > > > <?php > > > echo $form->input('fieldname.1'); > > > echo $form->input('fieldname.2'); > > > ?> > > > <input type="text" id="ModelnameFieldname1" name="data[Modelname] > > > [fieldname][1]"> > > > <input type="text" id="ModelnameFieldname2" name="data[Modelname] > > > [fieldname][2]"> > > > > The problem is when I do model.saveAll() it screws up because it > > > expects the data in this format: > > > data[1][Modelname][fieldname] > > > data[2][Modelname][fieldname] > > > > I know that is the expected model because of the comment above the > > > saveAll function: > > > @param array $data Record data to save. This can be either a > > > numerically-indexed array (for saving multiple records of the same > > > type), or an array indexed by association name. > > > > But validation errors won't display in the saveAll format. > > > > Because validationErrors array ends up looking like: > > > [ModelName][1][field] = "error message" > > > [ModelName][2][field] = "error message" > > > > But for the FormHelper to display the errors it needs to look like > > > this: > > > [ModelName][field][1] = "error message" > > > [ModelName][field][2] = "error message" > > > > So I have managed to work around it by using this in the view: > > > echo $form->input('Model.fieldname.1'); > > > echo $form->input('Model.fieldname.2'); > > > > And then I have a function that converts the $this->data for saveAll: > > > > function _prepareDataForValidation($data) { > > > $fixedData = array(); > > > > foreach ($data as $model => $fields) { > > > foreach ($fields as $field => $values) { > > > foreach ($values as $id => $value) { > > > $fixedData[$id][$model][$field] = $value; > > > } > > > } > > > } > > > > return $fixedData; > > > } > > > > And another function that puts the validationErrors in the right > > > format: > > > > function _fixValidationErrorsArray($validationErrors) { > > > $newValidationErrors = array(); > > > > foreach($validationErrors as $key => $fields) { > > > foreach ($fields as $field => $value) { > > > $newValidationErrors[$field][$key] = $value; > > > } > > > } > > > > return $newValidationErrors; > > > } > > > > Should I log this as a bug in trac? > > > > I really think FormHelper should be changed to be in this format: > > > > <?php > > > echo $form->input('Model.1.fieldname'); > > > echo $form->input('Model.2.fieldname'); > > > ?> > > > > instead of > > > > <?php > > > echo $form->input('Model.fieldname.1'); > > > echo $form->input('Model.fieldname.2'); > > > ?> > > > >https://trac.cakephp.org/ticket/4981issimilarto this, except I > > > don't have the belongs to association. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
