By masterpiece on
Hi,
I am using webforms in Drupal 6. I am embedding the same form in different nodes using this code:
$node = node_build_content(node_load(80));
print drupal_render($node->content);
If the form validates, everything works great. If the form doesn't validate, it redirects to the node id of the form, not the parent form. I can't get the validation function to redirect to the parent node on error. I am saving the node id of the parent node as a hidden field on the form.
Comments
Try this code
First off, out of box, I recommend you use JQuery's most excellent validate library so you can avoid the problem altogether. However, I realize not everyone can depend on JS being available 100% of the time.
Assuming you're using the Webform module that allows for PHP code for both additional validation and additional processing, you can try something along these lines:
In your additional validation, let's say your checking for an error as follows:
You could then include the following to re-direct back to the source node and include any error messages from failed validation.
Finally, you could add some code in Webform markup fields to printout a message if any parameters were passed in the URL.
By the way, just in case you want to go to a nid after validation passes, do this (assuming you called your hidden field 'nid'):
$node->webform['confirmation'] = 'internal:' . $form_values['submitted_tree']['nid'];Hopefully that at least gets you pointed in the right direction.
Regards,
Dan
Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.
didn't see this, thanks man,
didn't see this, thanks man, by the way is there a way to get notified everytime someone answers my post on this site ? I'm new to drupal
Unfortunately no...
You'd think this would be possible (like on groups.drupal.org), but alas it is not.
Once logging in, I typically visit my "Your Dashboard" link to view recent activity.
Regards,
Dan
Looking to Migrate from Drupal 6/7 to Drupal 10/11? Have a look at our Drupal 11 demo site and request access.
use hook_form_alter
hook_form_alter(&$form, $form_state, $form_id) {
if (substr($form_id,0,20) == 'webform_client_form_') {
$form['#action'] = $_SERVER['REQUEST_URI'];
}
}
use hook_form_alter
brilliant
Thanks, that still works a treat with D7 / webform 3.x.
I'm using a form in a block, so failed validation needs to redirect to the current page.
------------------
Phil Dodd
twitter: @phildoddau
a minor modification
When you aren't checking for any extra errors and you want the webform to redirect back to the same page that it's displayed on and still show messages when validation fails, for example when the webform is displayed as a block from a view, here is a modified snippet that you can place in the 'additional validation' section of webform 2.x: