Clear a form on submission

Clear a form on submission

by Kimber Warden -
Number of replies: 0

I have a Compose button in a block I've created. When clicked, a modal opens which contains moodleform fields for sending an e-mail (To, Subject, and Message). When the moodleform submit button is clicked, the modal closes and the e-mail is sent. I want the user to be able to immediately click on the Compose button again and fill out a new, empty e-mail form. Instead, the contents of the previous e-mail are displayed in the form. I've looked all over but can't find any reference to how to clear form fields on submission. I'm sure it's something simple, but I haven't been able to figure it out.


My form logic:

$mform = new sko_gmail_form();

if($mform->is_cancelled()) {

    $courseurl = new moodle_url('/course/view.php', array('id' => $id)); 

    redirect($courseurl);

} else if ($data = $mform->get_data()) {

    if (empty($data->subject)) {

        $warnings[] = get_string('no_subject', 'block_sko_gmail');

    }

    if (empty($data->recipient_email)) {

        $warnings[] = get_string('no_recipient', 'block_sko_gmail');

    }

if (empty($data->message)) {

        $warnings[] = get_string('no_message', 'block_sko_gmail');

    }

    if (empty($warnings)) {


        if (isset($data->send)) {

            $mform->send_gmail();


}


}


Is there something I can put after $mform->send_gmail() to clear the form fields?

Average of ratings: -