开发者

sfWidgetFormDate for sfWidgetFormInputText with two fields

开发者 https://www.devze.com 2023-03-15 09:37 出处:网络
I have the statement $this->setWidget(\'one_date\', new sfWidgetFormDate(array(\'format\' => \'%year%%month%\' )));

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:

sfWidgetF开发者_如何学GoormInputText does not support the following options: 'format', 'years'.


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');
}
0

精彩评论

暂无评论...
验证码 换一张
取 消