Form - How to Save the result in a table?

Form - How to Save the result in a table?

yazan Mario Lopes -
Yanıt sayısı: 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 yanıt olarak

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

yazan Davo Smith -
Core developers 'ın resmi Particularly helpful Moodlers 'ın resmi Peer reviewers 'ın resmi Plugin developers 'ın resmi

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 yanıt olarak

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

yazan 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 yanıt olarak

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

yazan Davo Smith -
Core developers 'ın resmi Particularly helpful Moodlers 'ın resmi Peer reviewers 'ın resmi Plugin developers 'ın resmi

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 yanıt olarak

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

yazan 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 yanıt olarak

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

yazan Joseph Rézeau -
Core developers 'ın resmi Particularly helpful Moodlers 'ın resmi Plugin developers 'ın resmi Testers 'ın resmi Translators 'ın resmi

@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 yanıt olarak

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

yazan 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 yanıt olarak

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

yazan Benjamin Ellis -
Particularly helpful Moodlers 'ın resmi

@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 yanıt olarak

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

yazan Mario Lopes -

 Bejamin

Great links 

thank you

Mario Lopes yanıt olarak

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

yazan 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