[symfony-users] Dynamic validation

2009-07-13 Thread nigelks

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
-~--~~~~--~~--~--~---



[symfony-users] multiple select box

2009-06-28 Thread nigelks

Hi,

I have a multiple select box which I am having trouble keeping the
values selected when the form is submitted and validation fails.

It looks to be a problem with the validation file and having fillin
enabled in html mode. If I change fillin to xml or xhtml mode the
options for the select remain selected when the form returns but all
my other data in text fields is removed.

So I thought just to remove the multiple select from the fillin and
populate the selected options myself. Now however I can't seem to get
the fillin to skip the select box using the skip_fields param. Here is
my fillin section of the validation file:
---
fillin:
  enabled: true
  param:
skip_fields: [etime_audiences]
---
I have also tried using skip_fields: [etime_audiences{}] as the name
of the select field is etime_audiences[].

Any help would be appreciated!

I'm using symfony 1.0.20

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---