Hi,

I have a module that defines 2 new node types. I am able to insert, delete, update, view etc these nodes just fine. Part of this module is a drupal menu that creates many of these nodes programmatically. It gets information from the filesystem and then creates nodes ( of my new type) with drupal_execute and outputs the results to the webpage.

Here I get an error. It seems that drupal execute does a 'form submission' behind the scenes, but after that it wants to take me to 'view' my new node, so the client is redirected and I end up on the view screen for the first new node. So I only get the first node created.

I experimented with using the drupal_execute example given in the docs, and if I use my code with a 'story' node it works. In other words, if I use the same code for parsing my filesystem and programmatically creating new nodes ( but as type story), it creates all my nodes and gives an expected out put screen with all the confirmations that the nodes were created.

So, obviously, there must be some way or hook to specify to create the node but just send the 'watchdog' message that the node was created rather than redirecting to the node view. Anyone know how I need to structure my hooks so this happens?

thanks,

Comments

dman’s picture

Did you try turning off the redirect?
$form['#redirect'] = FALSE;

... I haven't played with drupal_execute yet (tho I'd like to) so the issue may be a little deeper than this, but it's possibly relevant.
API on Form #redirect

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

meecect’s picture

It's unclear to me where I would put that. In the function where I am executing drupal_execute, I don't think I have access to the full form object. I have:

$node = array('type' => 'qcodo_page');
				$values['title'] = $title;
				$values['name'] = $user->name;
				$values['qform'] = $qform_content;
				$values['template'] = $template_content;
				$values['#redirect'] = FALSE;
				drupal_execute('qcodo_page_node_form', $values, $node);

putting redirect false there didn't change anything. I also tried putting it on the form that gets called:

function qcodo_page_form(&$node) {
  
  // title
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#default_value' => $node->title,
    '#required' => TRUE,
    '#weight' => 0,
    '#description' => t('Qcodo page title'),
  );

<SNIP>

  $form['#redirect'] = FALSE;
  return $form;
}

Still no effect. I'm beginning to think it has something to do with the difference between hook_insert and hook_submit. I don't have hook_submit defined, because I was following the node_example tutorial which just used hook_insert.

NaX’s picture

Try a drupal path

E.g.
$form['#redirect'] = 'admin/content';

I have also used hook_form_alter() to conditionally change the redirect page.

E.g.

function mymodule_form_alter($form_id, &$form) {
  if ($_GET['q'] == 'admin/mypath') {
    $form['#redirect'] = 'admin/mypath'
  }
}
wisdom’s picture

Have you resolved the issue? I come across similar problems. It sounds that drupal_execute does not handle the whole form submission property like redirection or action.

Online Business

tobiasoleary’s picture

Wisdom, you got some.

In D6 drupal_execute does not use the $form['#redirect'] value or $form_state['redirect'], which makes sense because it allows you to programmatically submit multiple form on the same page without having to worry about redirection.

If you want to force a redirect use drupal_goto, like someone else here suggested.
drupal_goto() doesn't appear to work in submit handlers (myform_submit).
I was doing something silly. drupal_goto works just place it at the end of the submit handler (myform_submit).

mooffie’s picture

Do you use drupal_goto() anywhere in your code?