dsfds2353 2014-07-17 10:20
浏览 23
已采纳

将错误设置为zend形式的字段

I have this form in Zend where the user should set up start & end date of something. I'm trying to invalidate the form / field if the end date is behind start date but it's not working. I overwritten the isValid() method and it worked but right now something else it's not working just because the isValid() method is overwritten.

how am i doing things:

$req = $this->getRequest();
$form->setAction($req->getRequestUri());

if($req->isPost() && $form->isValid($req->getPost())) {
    $startTime = strtotime(date($form->getValue('live_start')));
    $endTime = strtotime(date($form->getValue('live_end')));
    if($startTime > $endTime){
        $form->live_end->addError("End time shouldn't be earlier than start time !!!");
    }

If I use die; inside the if() it will die. So it's guaranteed that that if it's working. I used all kind of methods but it's not working.

Anyone have some ideas why it doesn't?

  • 写回答

1条回答 默认 最新

  • duancilan5124 2014-07-17 10:38
    关注

    I recommend you to :

    • Create a new validator, For example YouApp_Validate_Date_GreaterThan

    • Attach it to the live_end field.

    • Override your form isValid method, in such a way

    :

    public function isValid($data)
    {
        $this->live_end->getValidator('GreaterThan')->setDate($data['live_start']);
        return parent::isValid($data);
    }
    

    In your validator implementation, set the Date to compare to as a property to easily set it dynamically ->setDate($yourDate)

    Hope it helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch