0
votes

I have a page building a form with:

drupal_get_form('my_form_id')
my_form_id(&$form_state)
my_form_id_validate($form, &$form_state)
my_form_id_submit($form, &$form_state)

and saving in DB, my question is how can I edit data saved in another page? just loading the content from a table in DB and building the form filled with the data + edit button ?

In other words, I'm using Form API to build a form and save the node in DB, I want to build another form to edit that node.

Thanks.

1
could you please make the question more understandable........ - Vimalnath
hook_form_alter is used to edit the form - Vimalnath
yes vimalnath, I'm not sure I need hook_form_alter because I don't want to add/remove existing feilds, I just want to node_load into the form_state['values'] ? - Amin
@AminM why dont you use the default node/edit page? - frazras
@frazras it's loaded from my own table not a drupal's nodes, but I needed to use the same method of using the existing form functions but loaded with existing data (thus edit form). - Amin

1 Answers

1
votes

You could create a form then do a form alter to update the default values from an SQL query of your custom table.

function mymodule_form_alter(&$form, &$form_state, $form_id) {
    if($form_id == 'data_edit_form') {
      $form['formfield1']['#default_value'] = $data_from_query1;
      $form['formfield2']['#default_value'] = $data_from_query2;
      $form['formfield3']['#default_value'] = $data_from_query3;
    }
}