从mform获取循环文本值

问题描述

Mmform具有“计数”文本字段。当用户使用值3填充时,mform应该通过循环文本字段来创建“单元部件” (姓氏,名称文件管理器)。提交表单后,我需要显示用户填写的单位部分。 你能让我知道建议吗?

<?PHP     
require('config.PHP');
require_once($CFG->libdir.'/formslib.PHP');

class active_form extends moodleform {

    function deFinition()   {
            
        $mform = $this->_form;      
        $fileoptions = $this->_customdata['fileoptions'];
    
        $count = $mform->addElement('text','count',get_string('count','form'),array('name' => 'count[]');
        $count = $mform->setType('count',ParaM_INT);

        for ($i=1; $i<=$count; $i++) {

            // Unit
            $mform->addElement('text','forename',get_string('forename',array('name'=>'forename[]'));                        
            $mform->setType('forename',ParaM_RAW);

            $mform->addElement('text','designation',get_string('designation',array('name'=>'designation[]'));                       
            $mform->setType('designation',ParaM_RAW);          

            $mform->addElement('filemanager','attachment',get_string('attachment',null,$fileoptions);                         
            $mform->setType('attachment',ParaM_RAW);
        }       
       $this->add_action_buttons();     
    }

    function validation($data,$files) {
        $errors = parent::validation($data,$files);
        return $errors;
    }
}

$mform = new active_form(null,$customdata);

if ($mform->is_submitted()) { 

    $data = $mform->get_data();
    for ($i=1; $i <= $data->count; $i++) { 
        $forename = $data->forename;
        $designation = $data->designation;
        $attachment = $data->attachment;

        echo 'forename' . $forename. '<br>';
        echo 'designation' . $designation. '<br>';
        echo 'attachment' . $attachment. '<br>';    
    }       
} 

echo $OUTPUT->header();

$mform->display();

echo $OUTPUT->footer();

?>

ex:用户已填充

count: 3

forename = SVs Group
designation = Assistant Engineer
attachment = 676208496

forename = Prime Group
designation = Staff Member
attachment = 646759033

forename = Ecos Group
designation = Staff Member
attachment = 107025147

输出

count:3

forename: SVs Group
designation: Assistant Engineer
attachment: 676208496

forename: Prime Group
designation: Staff Member
attachment: 646759033

forename: Ecos Group
designation: Staff Member
attachment: 107025147

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)