用于Moodle中的文本字段组的addRule

时间:2015-09-09 09:28:46

标签: validation moodle required

如何在 Moodle 中添加text字段所需的规则。

 for ($i = 1; $i <= 4; $i++) {  
  $ansgroup = array(
           $mform->createElement('radio', 'answercorrect', '', '', $i, array('class' => "mock_answerradio", 'id' => "rad$i")),
           $mform->createElement('text', "answertext[$i]", '', array('size' => 30, 'id' => "text$i")),
            );
     $mform->addGroup($ansgroup, 'answer', 'Option-' . $i, array(' '), false);
     $mform->addRule('answertext[$i]', null, 'required', null, 'client'); //not working    
     $mform->setType("answertext[$i]", PARAM_RAW);
        }

我必须为addRule字段添加text。但没有运气。 我试过这样:

$mform->addRule('answertext[1]', null, 'required', null, 'client'); //not working

1 个答案:

答案 0 :(得分:0)

您可以这样使用:

$domaingrp = array();
$domaingrp[] = $mform->createElement('text', 'protocol', '', array('class' => "protocol autowidth", 'disabled' => "disabled", 'size' => '3'));

$domaingrp[] = & $mform->createElement('text', 'domainname', '', 'maxlength="100" size="50" class="tenantdomain turnintolower"');

$mform->addGroup($domaingrp, 'domaingrp', get_string('domainname', 'ext_tenant'), ' ', FALSE);

$mform->addRule('domaingrp', get_string('required'), 'required');