Someone came into the #symfony channel on freenode asking how to add conditional validators that would require a text box to be filled out when a checkbox was ticked. As I realize this is a common question (though the circumstances may change), I wanted to put this example up here as well, for others.
Here’s the example:
class TestForm
{publicfunction configure(){// ... snip ...$this->validatorSchema->setPostValidator(new sfValidatorCallback(array('callback'=>array($this,'contextualChecks'))));}publicfunction contextualChecks($validator,$values){if($values['checkbox_1']==1){if($values['textbox_for_checkbox_1']==''){$error=new sfValidatorError($validator,'Field is required when Checkbox 1 is checked.');$ves=new sfValidatorErrorSchema($validator,array('textbox_for_checkbox_1'=>$error));throw$ves;}}return$values;}}
Note: I completely left out returning $values in the initial draft. I apologize!
I have just made my first release to GitHub, majaxPheanstalkPlugin for symfony 1.4.x (possibly will work on older ones). It’s a set of tools that help to access Beanstalkd and make building workers much simpler.
The goal is to provide you with simple tools for managing your Beanstalkd integration. Right now it’s just worker thread tools and a simple factory, but I hope to grow it into a more complete library as time goes on.
Alright, I understand that in order to keep people checking back regularly, I have to post regularly.
I get that.
I really do!
Sometimes, though, life just takes over. I’m working on making that better.
To that end: Did anyone else attend the Day Camp 4 Developers session last weekend? If not, you missed a real riot. The speakers were excellent, and the crowd in IRC was just awesome.