I have Views providing a Block with a single Webform node in it. This Block is then placed on other nodes in the site. This works just fine, but when there is a submission error due to the form not passing validation, Webform displays the errors on the node/*** page with only the form displayed. This takes it out of the context of the original page.

My question is whether there is a way for Webform to display it's errors within the Block and not redirect to it's node page?

Comments

quicksketch’s picture

It's a tricky problem and it's the reason #248157: Allow any Webform to be displayed as a block is not an official feature. You might try this code in the header of your View (use the PHP input format):

if (isset($_POST['submitted']) && form_get_errors()) {
  return theme('status_messages');
}

Basically it's a crude check to see if a Webform submission has occurred, and if so, printout the status messages in the header of the block.

jschulz-1’s picture

Thanks a lot for that idea. It kind of works if I add this code to Additional Validation section (to return them to the same page instead of node/***).

if (form_get_errors()){
 drupal_set_message();
 drupal_goto('same_page');
}

That displays the messages in the Block then, but the forms fields don't get the "error" class set on them.

Also, it clears what the form values, so it's a blank form.

quicksketch’s picture

Component: Documentation » Code
Status: Active » Closed (duplicate)

Let's just consolidate the efforts in #248157: Allow any Webform to be displayed as a block. If we fix it there we don't have to keep making custom solutions every time someone wants to do this.