douyuan9512 2016-07-26 23:46
浏览 58

addRule问题 - 不验证数值HTML_QuickForm

I need to add validation for HTML_QuickForm. I tried but still cannot see any error message. This is the code I'm using.

$element = HTML_QuickForm::createElement('text','text1','Length');
$element->SetValue($app->GetLength());
$form->addRule('text1', 'Length should be a numeric value', 'numeric');
$form->addElement($element);

Once the form submitted,

if (isset($_POST['btnSubmit'])) {
    if($form->validate()){
        echo "form validated";
    }else{
        echo "validation fail";
    }
}

I always get "form validated" although text1 has text values.

UPDATE:

I could display an alert message changing the code to this:

$form->addRule('text1', 'Length should be a numeric value', 'numeric', null, 'client');

But I need to display an error message instead of alert. Also want to highlight the error field. In documentation says that QuickForm will automatically mark required fields in the form.

Any help on this would appreciate.

  • 写回答

1条回答 默认 最新

  • duannaoye0732 2016-07-27 10:31
    关注

    You have to set the field to be required. Otherwise empty values are not validated.

    评论

报告相同问题?

悬赏问题

  • ¥15 我的数据无法存进链表里
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端