Using a form to update data

Events happening in the community are now at Drupal community events on www.drupal.org.
mettam's picture

I'm in my first attempt at building a custom module and I've run into a problem I can't seem to find an answer for. It's a task I've done a millions times using various scripting languages, but despite hours pouring over the Forms API and other resources, I cannot figure out how I'm supposed to do this. And I'm sure someone is going to point to some simple thing I'm missing here....

I've built a form in a custom module that takes data from a user and puts it into a table. I can then use Views to build tables to display that data, another form that can do some general manipulation on the data, and I created a link from the data within the data display (using Views) that links to the original form. However, the piece I am missing is how do I pass a reference to the data so that I can load the data into the form and allow the user to edit their previous submission? I've found how to do it if it were a node, but it's not a node, so I'm stuck.

Anyone know the answer to this one?

Thanks

Comments

Can you just query the

attheshow's picture

Can you just query the database for the table row and then fill in the #default_value of each of the fields?

Mark W. Jarrell
Online Applications Developer
Richland Library
http://www.richlandlibrary.com
http://fleetthought.com
Twitter: attheshow

While that wasn't actually

mettam's picture

While that wasn't actually the piece I was missing, it did make me realize that I was over-thinking things. At which point I was able to find a way to deal with the missing link in the process... which was simply finding the function arg().

Now, as for the actual table update part, I've seen some code using separate Insert and Update submission processes, others where they delete the original data, if it exists and then do an insert with the changed data. Which is the better practice for Drupal? And either way I'm thinking I need to add a '#value' form field to indicate if the user is submitting a new or edited entry, or is there a simpler way to do that?

Thanks for the help!

Now, as for the actual table

kostajh's picture

Now, as for the actual table update part, I've seen some code using separate Insert and Update submission processes, others where they delete the original data, if it exists and then do an insert with the changed data. Which is the better practice for Drupal?

@mettam, take a look at drupal_write_record: http://api.drupal.org/api/function/drupal_write_record/6

Views Implementation

reid.braswell's picture

@mettam I am a creating a custom form in a .module file for a real estate firm. The form is designed to help agents in the firm keep up with important dates and client info. The form submits its data to a table in the Drupal database. I want to create a custom view so that when agents log in they can click a link in their navigation menu to see the data that ONLY they submitted (tie it to their username). How did you create your view to display the data from the table you created in the database? Thanks so much for your help.

Why not use CCK to generate

afreeman's picture

Why not use CCK to generate your form and get Views integration for free?

North Carolina

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week