I have added fields in a hook_form() and 3 of the fields are SELECTs with an "Add New" button that takes the user to a new form to add an entry to the possible values in the select. I need to save what the user was entering, pass it through the "Add New" form and re-populate the fields in the original form when the user has submitted the new entry and returned.

I think I need to save $_POST['edit'] somewhere, so I tried variable_set/get but it didn't repopulate the original form when I went back there.

Is there an official way to save form variables to repopulate the form when you get back to it?

Thanks,

David Cornelius

Comments

Anonymous’s picture

I finally figured it out. It wasn't so much of a Drupal issue, but a Drupal API helped simplify things.

To save the current form data...

  variable_set('saved_edit', $node);

The later to restore it...

  $saved_node = variable_get('saved_edit', '');
  if ($saved_node != '') {
    foreach ($saved_node as $key => $value) {
      $node->{$key} = $value;
    }
  }

At some point, the saved variable should be deleted...

  variable_del('saved_edit');

Hope that helps someone, someday.

David Cornelius

nicholas llewellyn’s picture

David, it looks like you've cracked exactly what I'm trying to do, but I don't understand what you have done...

I'm using CCK node and have made two two content types, call them A and B.

When creating content type A, I wish to reference node type B in a lookup field, but if the node doesn't exist already I need to give the option to create one, then return and continue filling in the details on A.

Do you possibly have some module names I might benifit from reading up on? Not knowing what to search for is a killer.

you can probably guess I'm a little green ;-)

Nick