Validation Moodle中文本字段组的addRule

Validation Moodle中文本字段组的addRule,validation,moodle,required,Validation,Moodle,Required,如何在Moodle中添加文本字段所需的规则 for ($i = 1; $i <= 4; $i++) { $ansgroup = array( $mform->createElement('radio', 'answercorrect', '', '', $i, array('class' => "mock_answerradio", 'id' => "rad$i")), $mform->createElement

如何在Moodle中添加
文本
字段所需的规则

 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);
        }
您可以这样使用:

$mform->addRule('answertext[1]', null, 'required', null, 'client'); //not working
$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');