Hi,
I am creating a new node type that requires that parameters are passed to it in the command line (ie. /node/add/type/12/12).

I am checking in hook_form as the very first item to ensure that arg(3) and arg(4) are being passed.

If they are not passed, then I issue an error using form_set_error() and then return; without passing any form information.

But what happens is I stay on the form and get no fields displayed, and a save and preview button.

I'd like to just redirect to the previous page, or perhaps the home page and display the error.

Can this be done? is there a better place to do it?

I am checking in the hook_validate that the values are set, but its all too late at that point.

any advice appreciated,
thanks

Comments

Jaypan’s picture

Advice: can't get help if you don't show code.

ozecho’s picture

Not sure if I was approaching it right, but here is the code that I put at the top of hook_form

function project_form($node) {
 if (arg(1)=='add') {
   if (arg(3)) {                                               // there is a project type passed     
      $project_node = node_load(arg(3));
      if ($project_node->type != 'projecttype') {
         form_set_error('project', t("Bad project type passed.  Please restart the process."));  
         return $form;
      }
   }
   else {
         form_set_error('project', t("No project type passed.  Please restart the process."));  
         return $form;
   }
 }

When it falls into the error condition, the error is displayed but it stays on the add page with the "save" and "cancel" buttons. I'd like to redirect it to another page.

Is that possible?

Should I approach this another way? Is there a earlier place that I can check that arguments are being passed to a node/add ?

thanks for your help...

Jaypan’s picture

else {
         form_set_error('project', t("No project type passed.  Please restart the process.")); 
         drupal_goto('other/page');
   }
ozecho’s picture

Thanks Jay... worked perfectly!