I get the following error when trying to pass through an option to my buildForm
method in one of my forms.
The option "numOfHoles" does not exist. Defined options are: "action", "allow_extra_fields", "attr", "auto_initialize", "block_name", "by_reference", "cascade_validation", "compound", "constraints", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "error_mapping", "extra_fields_message", "inherit_data", "intention", "invalid_message", "invalid_message_parameters", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "validation_groups", "virtual".
In my controller:
// hardcoded here for brevity in this example
$form = $this->createForm('crmpicco_course_row', $courseRow, array('numOfHoles' => 18));
In crmpicco_course_row
Form class:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text')
->add('course', 'crmpicco_course', array('numOfHoles' => $options['numOfHoles']))
;
}
In crmpicco_course
Form class:
public function buildForm(FormBuilderInterface $builder, array $options)
{
for ($i = 0; $i < $options['numOfHoles']; $i++) {
$builder->add($i, 'text', array('required' => 'false'));
}
}
/**
* @return string name
*/
public function getName()
{
return 'crmpicco_course';
}
Can anyone see why the option numOfHoles
is not pulling through?
numOfHoles
option using thesetDefaults
orsetRequired
function inside theconfigureOptions(OptionsResolver $resolver)
of your form builder. – gp_sflover