Counget Counget
Counget Counget

Reputation: 1

sfWidgetFormDate for sfWidgetFormInputText with two fields

I have the statement

$this->setWidget('one_date', new sfWidgetFormDate(array('format' => '%year%  %month%' )));

one_date in MySQL is a timestamp. This shows me the selected list with year and selected list with month. How can i change this for input text for month and input text for year? If I try changing with: sfWidgetFormInputText then I have an error:

sfWidgetFormInputText does not support the following options: 'format', 'years'.

Upvotes: 0

Views: 1103

Answers (1)

Peter Hough
Peter Hough

Reputation: 560

You would need two separate text fields that you combine after submission to create your one_date.
Doing it this way could make validation tricky.

$this->setWidgets(array(
      'month' => new sfWidgetFormInputText(),
      'year' => new sfWidgetFormInputText()
   ));
$this->setValidators(array(
      'month' => new sfValidatorInteger(),
      'year' => new sfValidatorInteger()
      ));
if ($this->form->isValid()) {
      $one_date = $this->form->getValue('month') . $this->form->getValue('year');
}

Upvotes: 1

Related Questions