Hi, I'm trying to write a module where the user will submit a link (say to IMDB) and then this will go off and use the IMDB API or scrape the page, filling in the rest of the values on the form.

I want to do this in two steps - fill in the URL value, then have a button 'retrieve info' which will then populate the fields, but leaving the form as unsubmitted yet, so the user can review/add additional information.

Any tips on how to achieve this multi-step process?

Being able to call a form with pre-specified values (without having those values in the URL) would be helpful as a basic possibility? Can this be achieved passing the info around $form_state?

Cheers!

Comments

venkatd’s picture

I am also trying to do the same thing. I tried doing the following but it doesn't work:

/**
 * Implementation of hook_form_alter()
 */
function productinfo_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'product_node_form') {
    $form['buttons']['productinfo'] = array(
      '#type' => 'submit',
      '#value' => 'Fill Product Info',
      '#weight' => 11,
      '#submit' => array('productinfo_fill_info'),
    );
  }
}

function productinfo_fill_info(&$form, &$form_state) {

}

In the productinfo_fill_info function, I tried altering the $form_state['values'] array and I also tried altering the $form itself. But neither of these seem to work.

Any advice is appreciated.

venkatd’s picture

Made a bit of progress. If I set $form_state['rebuild'] = TRUE, then I can modify the values in $form_state. (Not 100% sure why this is the case.)

For example,

function productinfo_fill_info(&$form, &$form_state) {
  $form_state['values']['field_link'][0]['value'] = 'http://www.google.com';
  $form_state['rebuild'] = TRUE;
}

For some reason, some existing fields such as the title and the taxonomy select box are getting reset. I'm not sure why this is the case.