Reputation: 981
How can I check in symfony 1.4 if a value is a specific string.
In my html-code I enter a default-value:
<input ... value="Recipe name.">
My current form:
$recipename_value = 'Recipe name.';
$this->setWidgets(array(
'recipename' => new sfWidgetFormInputText(array(), array('size' => '40', 'maxlength' => '150',
'value' => $recipename_value,
$this->setValidators(array(
'recipename' => new sfValidatorString(array('max_length' => 150), array(
'required' => 'Please enter a recipe name.'
)),
The sfValidator should give an error message when the value is Recipe name.
How can I do it in symfony? I read a lot about max_- & min_length and sfValidatorSchemaCompare, but nothing with string. Can somebody help me?
Thanks!
Gunnar
Upvotes: 0
Views: 387
Reputation: 2014
You can use postValidator In your form class:
public function checkValue($validator, $values) {
if ($values['recipename']=="Recipe name."){
$message = 'Your message';
throw new sfValidatorError($validator, $message);
}
else{
return $values;
}
}
BUT , I think the true way for you is to use placeholder for your form field. You can read about it:
And plugin for IE:
jQuery HTML5 Placeholder Plugin
Upvotes: 1