dongxi7609 2013-06-17 18:07 采纳率: 0%
浏览 28

对于Zend表单,如何将结束日期更新为自输入开始日期的开始日期后一天?

I have a start date element and an end date element in a form. Each are selected using a datepicker. I would like my form to automatically set the end date element of my form to be one day after the start date is selected (so, for example, if I select July 10, 2013, the value in the end date field should default to July 11, 2013). The user can make the end date whatever they want to from then on, but initially it should be the day after.

Here is my code for the form:

    // Element: start_date
    $start_date = new Zend_Form_Element_Text('start_date',
        array(
             'label' => 'Start date',
             'required' => false,
             'filters' => array('StringTrim', 'StripTags'),
             'class' => 'input-small datepicker',
             'decorators' => $customElementDecorators,
             'data-date' => date("Y-m-d"),
             'data-date-format' => 'yyyy-mm-dd',
             'value' => date("Y-m-d")
        )
    );

    // date validator
    $start_date->addValidator(new Zend_Validate_Date('Y-m-d'));

    $this->addElement($start_date);
    unset($start_date);

    // Element: end_date
    $end_date = new Zend_Form_Element_Text('end_date',
        array(
             'label' => 'End date',
             'required' => false,
             'filters' => array('StringTrim', 'StripTags'),
             'class' => 'input-small datepicker',
             'decorators' => $customElementDecorators,
             'data-date' => date("Y-m-d"),
             'data-date-format' => 'yyyy-mm-dd',
             'value' => date("Y-m-d")
        )
    );
    $this->addElement($end_date);
    unset($end_date);

Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douwen5546 2013-06-17 18:12
    关注

    When you set the data-date property for the end assign it the value of date("Y-m-d", strtotime("+1 day"));

    $end_date = new Zend_Form_Element_Text('end_date',
        array(
             'label' => 'End date',
             'required' => false,
             'filters' => array('StringTrim', 'StripTags'),
             'class' => 'input-small datepicker',
             'decorators' => $customElementDecorators,
             'data-date' => date("Y-m-d", strtotime("+1 day")),
             'data-date-format' => 'yyyy-mm-dd',
             'value' => date("Y-m-d")
        )
    );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答