how to not submit part of the form when it is empty
I have the following code that creates a form:
class ShippingInfoType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', 'text')
->add('lastName', 'text')
->add('phoneNumber', 'text')
->add('location', new LocationType(),
array('cities'=>$options['cities']))
->add('user', new UserType(), array('mode' =>
'register_temp'))
;
}
}
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
switch ($options['mode']) {
case 'login':
$builder
->add('email', 'text')
->add('password', 'password')
;
break;
case 'register_temp':
$builder
->add('email', 'text')
->add('password', 'repeated', array(
'type' => 'password',
'invalid_message' => 'The password fields must
match.',
'options' => array('attr' => array('class' =>
'password-field')),
'required' => false,
'first_options' => array('label' => 'Password'),
'second_options' => array('label' => 'Repeat
Password'),
));
;
break;
...........
}
The issue is that I want such that when the user doesn't enter the
password and confirm password, I don't want it to bind to the form (in
other words, ignore as if I didn't add password field/input to the form).
I've added the password as not required, however when I run this it always
gives me a redirect loop to login. Is such thing possible?
No comments:
Post a Comment