jeudi 26 mars 2015

Symfony check validation for non exist field

This is my form



class CandidateType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
->add('dob')
->add('user', new CandidateUserType());
}

public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'AppBundle\Entity\Candidate',
'cascade_validation' => true,
));
}

public function getName()
{
return 'candidate';
}
}


In my first screen system get only first_name last name and user details. I need use this form in second screen. But I no need to show first name and last name fields in that view. I really need show only birth day.


So i show my form like this.



{{ form_start(form, {'attr': {'id': 'candidate_form', 'class': 'form-horizontal'}}) }}

{{ form_errors(form) }}

<div class="row">
<div class="form-group">
<label>DOB</label>
{{ form_widget(form.dob, {'attr': {'class': 'form-control'}}) }}
{{ form_errors(form.dob) }}
</div>
<div class="col-sm-12 col-xs-12">
<button type="submit" class="btn btn-primary btn-lg pull-right">
COMPLETE
</button>
</div>
</div>

{{ form_row(form._token) }}
{{ form_end(form, {'render_rest': false}) }}


I have used render_rest for not show unwanted field. But system check validation for firstName, lastName and user field also.


This question might be duplicate. What is the correct way to do this? Should i implement another form for show dob of candidate?


Aucun commentaire:

Enregistrer un commentaire