Form - How to Save the result in a table?

Form - How to Save the result in a table?

Napisane przez: Mario Lopes ()
Liczba odpowiedzi: 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

W odpowiedzi na Mario Lopes

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

Napisane przez: Davo Smith ()
Obraz Core developers Obraz Particularly helpful Moodlers Obraz Peer reviewers Obraz 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.

W odpowiedzi na Davo Smith

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

Napisane przez: 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? 

W odpowiedzi na Mario Lopes

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

Napisane przez: Davo Smith ()
Obraz Core developers Obraz Particularly helpful Moodlers Obraz Peer reviewers Obraz 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.

W odpowiedzi na Davo Smith

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

Napisane przez: 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

W odpowiedzi na Mario Lopes

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

Napisane przez: Joseph Rézeau ()
Obraz Core developers Obraz Particularly helpful Moodlers Obraz Plugin developers Obraz Testers Obraz 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

W odpowiedzi na Joseph Rézeau

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

Napisane przez: 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

W odpowiedzi na Mario Lopes

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

Napisane przez: Benjamin Ellis ()
Obraz 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

W odpowiedzi na Benjamin Ellis

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

Napisane przez: Mario Lopes ()

 Bejamin

Great links 

thank you

W odpowiedzi na Mario Lopes

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

Napisane przez: 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