I am developing two form input modules based on the Drupal Form API. Specifically I made a variation of the my_module module created in example 7 of the following guide: http://drupal.org/node/262422.
The forms work great, they take the input which I later write to the db, however, after doing this write to db I want the module to redirect the browser to another webpage.
I have tried to use php's header() function as follows:
header('Location: http://localhost');
As well as drupal's drupal_goto() function as follows:
drupal_goto($path = 'http://localhost', $http_response_code = 302);
and as
drupal_goto('http://localhost');
But I keep getting the following Firefox Error:
Redirect Loop
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
Can anyone suggest a way to redirect after the _submit function concludes?
Thanks!
Comments
Is the form located at
Is the form located at http://localhost ?
The form is located at
http://localhost/reply_module/form
Here's the module's code:
It is that last else statement that would redirect in case the user is not allowed to access the page (failing the if) but Firefox produces the infinite looping error
any ideas/suggestions?
Here is why - all module
Here is why - all module files are read by the php interpeter at run time for each request. SO, since: if (user_access('access reply module' || 'administer reply module')) {
is not in a function, it gets evaluated for each request.
here is what i would do.:
I hope the above helped, if it needs clarification, just ask
Use the menu system to perform the access check, useing the array key 'access arguments' It will give a 403 if they cant get to it - which is better than sending then to some page and now saying why. You can also declare drupal_get_form directly from the menu as the page callback.
Cannot access module even as admin
Thank you Brian for your suggestion, it was pretty clear what you did. I tried it, but cannot access the module any longer, not even as admin. The browser displays the same blank screen as before, and when I navigate to a viewable location (say http://localhost) I see the following error (in the red drupal message box at the top of the page) as well as the viewable page:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'report_module_form' was given in /var/www/includes/menu.inc on line 348.Are you sure your code is exact? Any other suggestions anyone? I'm sure we're moving in the right direction...
thanks to all
gtb
Have you gone back to the
Have you gone back to the modules page? after maing any changes to the menu system, you have to flush the menu cache. going to the modules page will do this.
Thanks Seagraves,
I modified my code as suggested by Brian:
I removed the if statement from the module file and changed the 'access arguments' item on the $items['report_module/form'] array to => array('access report module') leaving it as:
This solved the issue of denying access to the form. When the submit function finished, I simply used the drupal_goto() function to send the user to another page.
Thanks a bunch Brian!
gtb