0

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

1 Answer 1

1

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:

HTML5 placeholder Attribute

And plugin for IE:

jQuery HTML5 Placeholder Plugin

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.