Hi,
I have a form that captures guest information but the form is related
to a event in which the administrator can change the required fields
i.e. one event may want the preferred name while another may not.
I have created a validation file with all the fields for this form and
created my own custom validator that checks if the field is required.
The problem I'm having is I can't seem to get the validator to run
correctly as I can't set the field to required but I want it to run my
custom validator. I have also tried adding a group to the fields but
this make all the fields required.
Any ideas?
Here is what I have so far
edit.yml
-
validators:
regFormValidator:
class: myRegFormValidator
param:
hidden_etime_id: etime_id
reg_error: This field is required
fields:
etime_id:
group: validate_me_group
required: true
msg: Missing etime id
guest{title}:
group: validate_me_group
msg: Please select a title
required_msg: Please select a title
regFormValidator:
field: title
reg_error: Please select a title
guest{firstname}:
group: validate_me_group
msg: Please select a firstname
required_msg: Please select a firstname
regFormValidator:
field: firstname
reg_error: Please select a firstname
guest{preferred_name}:
group: validate_me_group
msg: Please select a preferred name
required_msg: Please select a preferred name
regFormValidator:
field: preferred_name
reg_error: Please select a preferred name
---
myRegFormValidator.class.php
---
setParameter('reg_error', 'This field is required');
$this->getParameterHolder()->add($parameters);
return true;
}
public function execute(&$value, &$error) {
$field_value = trim($value);
$etime_id_param = $this->getParameter('hidden_etime_id');
$etime_id = $this->getContext()->getRequest()->getParameter
($etime_id_param);
$field = $this->getParameter('field');
$c = new Criteria();
$c->add(EtimePeer::ID, $etime_id);
$etime = EtimePeer::doSelectOne($c);
$c = new Criteria();
$c->add(RegFieldPeer::NAME, $field);
$regField = RegFieldPeer::doSelectOne($c);
$c = new Criteria();
$c->add(RegFormPeer::EVENT_ID, $etime->getEvent()->getId());
$c->add(RegFormPeer::REG_FIELD_ID, $regField->getId());
$regForm = RegFormPeer::doSelectOne($c);
if ($regForm->getRequiredField() && $field_value == "") {
$error = $this->getParameter('reg_error');
return false;
}
return true;
}
}
Thanks,
Nigel
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en
-~--~~~~--~~--~--~---