Form - How to Save the result in a table?

Form - How to Save the result in a table?

av Mario Lopes -
Antall svar: 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

Gjennomsnittlig vurdering: -
Som svar til Mario Lopes

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

av Davo Smith -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av 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.

Som svar til Davo Smith

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

av 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? 

Som svar til Mario Lopes

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

av Davo Smith -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av 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.

Som svar til Davo Smith

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

av 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

Som svar til Mario Lopes

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

av Joseph Rézeau -
Bilde av Core developers Bilde av Particularly helpful Moodlers Bilde av Plugin developers Bilde av Testers Bilde av 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

Som svar til Joseph Rézeau

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

av 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

Som svar til Mario Lopes

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

av Benjamin Ellis -
Bilde av 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

Som svar til Benjamin Ellis

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

av Mario Lopes -

 Bejamin

Great links 

thank you

Som svar til Mario Lopes

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

av 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