Form - How to Save the result in a table?

Form - How to Save the result in a table?

Mario Lopes -
回帖数:10

Hi
I create a form with the help of the link
http://docs.moodle.org/dev/lib/formslib.php_Form_Definition
My question is: how to save one text value 


$mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25" ');

in my table ?

Thank you

回复Mario Lopes

Re: Form - How to Save the result in a table?

Davo Smith -
Core developers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Look at http://docs.moodle.org/dev/lib/formslib.php_Usage for how to set up a form and gather the data back from it, then use the database API ( http://docs.moodle.org/dev/Data_manipulation_API ) to save the data into a table.

There are hundreds of examples of forms in the Moodle core code, so you should be able to find something similar to what you are wanting to do.

回复Davo Smith

Re: Form - How to Save the result in a table?

Mario Lopes -

Thank you Davo
I need a code similar to this one

$DB->insert_record($table, $dataobject, $returnid=true, $bulk=false)

Where to put this code? In the form that I have create? In other php file?
I want to develop a moodle module and I saw this instrution  $this->add_action_buttons(); what this mean?
Any help, please? 

回复Mario Lopes

Re: Form - How to Save the result in a table?

Davo Smith -
Core developers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

Like this:

if ($data = $form->get_data()) {
$ins = new stdClass();
$ins->myfield1 = $data->myfield1;
$ins->myfield2 = $data->myfield2;
$ins->id = $DB->insert_record('mytable', $ins);
}

As already stated, there hare hundreds of examples like this in the Moodle core code, I'm sure you can find one that fits what you are trying to do.

回复Davo Smith

Re: Form - How to Save the result in a table?

Mario Lopes -

Once more thank you for your help . Sorry about my question but where (or waht) is the Moodle core code? The problem is there are hundreds of stuff in the Moodle website and it's not easy to find what I need. Please can you point me in the right direction?

Regards

回复Mario Lopes

Re: Form - How to Save the result in a table?

Joseph Rézeau -
Core developers的头像 Particularly helpful Moodlers的头像 Plugin developers的头像 Testers的头像 Translators的头像

@Mario,

The "Moodle core" consists of the totality of the files in your Moodle folder, with the exception of files related to 3rd-party plugins that have -maybe- been added to your Moodle site.

You do not say what exactly you are trying to do. Are you trying to hack an existing Moodle plugin? Or to create a new one? Or to create a new "block"? Unless you are creating something totally new and "exotic", the best way to go is to base your work on an existing plugin or block, so you can understand how it works, and familiarize yourself with the Moodle API.

Joseph

回复Joseph Rézeau

Re: Form - How to Save the result in a table?

Mario Lopes -

Hi Joseph

I want to create a new block will allows teachers to post his curriculum vitae. I think I can handle it. 

Thank all for help me

回复Mario Lopes

Re: Form - How to Save the result in a table?

Benjamin Ellis -
Particularly helpful Moodlers的头像

@Mario,

I only started serious Moodle development 2 months ago and found that working though the example on http://docs.moodle.org/dev/Blocks
and followed by the 'Unit 7 of the Introduction to Moodle Programming course'
helped me a lot in getting to grips with the code base. I have since written about 6 plugins for my employer

回复Benjamin Ellis

Re: Form - How to Save the result in a table?

Mario Lopes -

 Bejamin

Great links 

thank you

回复Mario Lopes

Re: Form - How to Save the result in a table?

Mario Lopes -

I'm back again

I try do create a block (simplehmtl) with the links that Benjamin posted. Everything went fine but when I try http://dev.moodle.org/mod/page/view.php?id=49  I can't see any addpage link in my block as described in this article (...You can test it by clicking on the addpage link in the footer of the block) . What's wrong with my code? If anyone want to help me please download my code from my website and point me in the right direction.

http://www.mariolopes.com/simplehtml.zip

Regards