By npollock on
I submitted a similar question to this, but maybe didn't word it well.
I don't know how to create link from a form item to a database field. I can create the form, but where or how do I tell the form what database field should be updated once the form is submitted?
Thanks
Norm
Comments
What kind of form?
What did you make the form with? flexinode? Another module?
Here it is
Here is the function I created that displays the form:
function poker_adminl() {
// League create settings.
$form['league_add'] = array('#type' => 'fieldset', '#title' => t('Create a new poker league'));
$form['league_add']['league_name'] = array('#type' => 'textfield', '#title' => t('League Name'), '#maxlength' => 30 );
$form['league_add']['league_description'] = array('#type' => 'textfield', '#title' => t('Description'), '#maxlength' => 30 );
return system_settings_form('poker_league_settings', $form);
}
and here is the mysql table:
CREATE TABLE leagues (
id int(10) unsigned NOT NULL auto_increment,
name text NOT NULL,
description tinytext NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
I have not done anything with the second set of brackets in the form.
Norm
*shrug* :-/
Sorry, but this exceeds what I have done with forms yet.
I guess you have to tell drupal what to do with the POST data by naming the form elements and implementing a handler for them.
Forms & Databases
Form values do not appear automagically in the database (unless you're working with hook_settings).
Start by reading the Forms API Quickstart Guide.
You need to return drupal_get_form(form_id, form_array), then you can validate the form with the function form_id_validate and finally act on the submitted form in form_id_submit. There you'll need to insert the data in the database by executing SQL queries.
This is explained in the Quickstart Guide mentioned above.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
I can't find it
I just read the API quickstart guide for the third time and I still don't see any reference to updating database fields from a form. I guess I will just have to keep looking. I heve been reviewing existing code to figure these questions out, but it is not easy. Updating database tables appears to be particularly elusive, but I will keep looking. If I can just get a single example that I can understand, I will be on my way.
Norm
SQL
For example (from the Quickstart Guide):
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
Thanks
I guess I didn't know submit form referred to submitting the results of the form. Thanks for your help, I think that I am getting closer now. Looking at user.module should help now that I know what to look for.
For people that know this systemm, the docs probably appear to be decent, but if you don't know the system, it takes a lot of reading and searching to find what you are looking for.
I appreaciate your responses though. Hopefully I can get the rest of the way there now.
Norm
here is what you need
http://drupaldocs.org/api/head/file/contributions/docs/developer/example...
see module code for examples of inserting data to tables
There are plenty of examples of how to do this within the source code of various modules. For example: Checkout node.module and comment.module ...
There many other examples within countless modules.
spritefully yours
spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...
Examples
I admit to being a PHP and mysql newbie, but I have spent a lot of hours searching forums, modules and handbooks to figure out how to develop in drupal. I see that there are a lot of examples and I keep looking at them, and for some reason,. I just can't figure out the correlation between the code and what is happening in the background. They are all more complex than what I am looking for.
Maybe what I am asking for is strange, but I would just like to see an example of a simple function that allows a user to update a field or two and then after clicking submit, inserts the data into the database.
I found a 4.6 example, but it appears to be different than 4.7.
Does anyone have a simple function that they could share that does what I am looking for?
Thanks
Norm
Strange you haven't found :-)
Maybe what I am asking for is strange, but I would just like to see an example of a simple function that allows a user to update a field or two and then after clicking submit, inserts the data into the database.The node_example.module works with 4.7 and fits exactly your request. Did you have a look ?