doutang7661 2016-09-28 10:11
浏览 48

定制moodle注册表单

I need to add attachment input to moodle sign up form
This file input is not supported by moodle through the standard user profile fields.

So I tried to add it manually:
I added:

$mform->addElement('file', 'attach', "Attach", null,array( 'accepted_types' => 'pdf'));
$mform->setType('attach', PARAM_RAW);
$mform->addRule('attach', 'Missing File Attachment', 'required', null, 'client');

But where should I tell Moodle to insert that value into the database?

  • 写回答

1条回答 默认 最新

  • dortmundbvb0624 2016-09-28 13:13
    关注

    You should probably first add a custom user profile field, as described here. Here you should override the function profile_save_data($usernew) to tell the system where you want to save your file.
    If you want to learn how to get the file from the form and save it you can go here. In particular, you could use the filepicker form element, which replaces the old file element, with

    $mform->addElement('filepicker', 'userfile', get_string('file'), null,
                       array('maxbytes' => $maxbytes, 'accepted_types' => 'pdf'));
    


    Get the file content and file name as well as store it with:

    $content = $mform->get_file_content('userfile');
    $name = $mform->get_new_filename('userfile');
    $success = $mform->save_file('userfile', $fullpath, $override);
    

    where $fullpath is a path in the file sytem (such as the moodledata folder) and $override is a boolean meaning "override file if exists".
    DISCLAIMER: I did not try this solution myself.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP