First off - awesome module, we use it on nearly every site we build. Great job, and thanks for keeping it current!
I have a Webform enabled as a block, and assigned to the sidebar_left region in the blocks system. I am actually using the region within the content area of a node as opposed to the page template, so have the following code in my theme_preprocess_node function:
$vars['sidebar_left'] = theme('blocks', 'sidebar_left');
The Webform is showing up and submits fine under normal circumstances, but if you have validation errors it redirects to the main Webform page instead of staying on the page it was a block on.
Am I missing a setting somewhere, or is there some context that is not getting set in Webforms at the theme_preprocess_node level that is screwing up the validation redirect? Any help would be greatly appreciated!
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | webform.png | 123.27 KB | Liaz |
Comments
Comment #1
arpieb commentedOK, just discovered that after changing the Webform's Redirection location to No redirect (reload current page) at the request of QA that it's also redirecting to the form page on from submission...
Comment #2
johnxer commentedI have the same problem.
Comment #3
3cwebdev commentedSame issue.
Comment #4
arpieb commentedHere's a fix that we came up with, placed in a hook_form_alter() callback for our forms:
The registered submit handler from above is:
So far it looks like it works great for our specific cases, but your mileage might vary...
Comment #5
3cwebdev commentedThanks for the code. I have tried it but it doesn't seem to work for me. I have verified that the custom submit handler is getting added to end end of the '#submit' array but it is not being called for some reason. It appears that the submit handler is simply being ignored and the webform page gets loaded instead of the block the same as before. Any idea what could be wrong?
Comment #6
wolfmarter commentedI have the same problem and also for the confirmation page
Comment #7
arpieb commented@setfree - mind posting your code (the hook_form_alter and submit handler) so we can see if maybe there is something in it that might not be getting picked up properly by the FAPI processing code? If you don't feel comfortable posting publicly, feel free to shoot it to me via PM and I would be more than happy to check it out...
Comment #8
3cwebdev commentedSure, thanks for offering to assist.
The complete code is below. I have tested and verified that the form ID is correct and that the new submit handler is being added to #submit as expected but the submit handler function is not being called.
Comment #9
arpieb commented@setfree, your code looks fine to me... Only thing I can think of - and please don't take this as being condescending as it's not meant as such - did you define the constant REDIRECT_OVERRIDE in your code?
I'm looking at the snippets and just realized I was using a defined PHP constant from my module (I tend to do that for strings as well as numeric values in an attempt to reduce typo errors - blame it on my C/C++ roots). If that value is not defined, all the $form and $form_state array assignments using that as a key will fail. In fact, if you have strict PHP error reporting set, it should fail spectacularly. ;) Alternatively, you could just replace that constant with a string key instead of using a constant like I did - all up to your coding style.
If you had that covered already, then I'd say drop a drupal_set_message call at the top of the submit callback to dump out the $form_state array and we can see if something is arranged differently from what I was getting. Note I am running Webforms 6.x-3.14 on a D6.22 installation, no idea how this code might work on a different release of Webforms OR Drupal.
Let me know what you find out and maybe we can figure out how to get that workaround to, well, work for you!
Comment #10
3cwebdev commentedThanks for your help with this. I really appreciate it! You were correct in pointing out the constants, I had not defined them. I replace the constant with the string, "redirect_override", but am still having the same issue. The submit handler is not being called even though the callback appears to get added to submit correctly. See snippet:
However, when I place a watchdog() function at the top of the submit callback, I see that it is never called. I have looked over the code and flushed the caches and have no idea why ccc_custom_code_webform_redirect_override() never gets called.
Any ideas what would cause this?
Complete Module
Comment #11
BillyMG commentedThanks for that code. I've managed to get a working custom module for my code, but mine is Drupal 7. It's very similar to your code, but with the D7 changes. I don't know if it would work in a subdirectory, but that should be a very easy fix. If we could just get these changes built into the module, setfree might not have to worry about it. I took a look at his code and nothing seemed immediately wrong.
Drupal 7 Module:
CUSTOM_MODULE: Name of your custom module
WEBFORM_FORM_ID: id of the Webform
Comment #12
favrik commented@BillyMG Just FYI, your code works fine on D6. Thanks! :)
Comment #13
3cwebdev commented@BillyMG, worked perfect on my D6 install too! Thanks :)
Comment #14
quicksketchThis is actually a bug in Webform. Separately reported over here: #1337784: Selecting "No redirect" does not reload current page..
Comment #15
quicksketchComment #16
finex commented@BillyMG: works fine on D7... thanks :-)
Comment #17
fbreckx commented@BillyMG: can u tell me where to implement this code? I'm relatively new to Drupal (and most definitely to php).
Comment #18
arpieb commented@fbreckx - The code is intended to be placed in a custom module as it leverages several Drupal callbacks related to forms. If you are not familiar with building modules, I would strongly recommend reading the docs here - Module developer's guide.
Comment #19
joecanti commentedI couldn't get this to work on D7 - probably through my own mistake.
A nice little fix for this is to use the clientside validation module - keeps the validation errors on the same page even if in a block, in a panel or wherever, and puts them next to the form.
Joe
Comment #20
fbreckx commentedOkay, thanks! I'll certainly read that information.
In the meanwhile I solved the problem using client side validation.
Comment #21
Liaz commentedFor drupal 6 and webform 3.17 the #11 works indeed perfectly - Thanks a lot @BillyMG !
Little modification for my personnal case: I wanted that the error page reloads on the current page where I have my form in a block, but I wanted the confirmation page to follow the redirection I set in the webform redirection location. For that, I just had to not call the redirect_override in the form submit but only the get_current_path in the form action.
So for my purpose the module is then :
Hope it will help some :)
Liaz
Comment #22
banense commentedVery simple,
go to admin/block edit your webform block and check "Show all webform pages in block" and all errors display in block not in node.
Regards
Comment #23
sozonov commentedCool!
Comment #24
quirogapj commented@banense nice and simple way to fix this! Thanks for share. Regards.
Comment #25
robriley78 commentedThere it is!! Thanks.
Comment #26
dco commentedNice trick banense, also works in D7 !
This checkbox description should be more explicit I think...
Comment #27
espurnes#11 works for me in D7.18 and webform 7.x-3.18.
Thank you!
But the same functionality is achieved with #22. No need to create a custom block.
Comment #28
justindodge commented#22 works great for me as well.
For a code solution that does this for all webform blocks, we used this snippet (D7) inside a hook_form_alter, it's a little simpler than #11. The redirect for success will inherit the settings setup in the webform.
Comment #29
vergil commentedhey everyone i am a newbie to drupal i am from Jamaica and i am having the same problem here but so for in my studies i only know Html and Css so this PHP stuff i am kinda clue less... wish i had a tooter
Comment #30
hockey2112 commented#22 did it for me. Thanks!
Comment #31
julescone commentedLegend banese! (#22) I thought it might be nice to know that a little answer you posted a year ago is still of use to someone!
I had overlooked that checkbox in my webform block configuration.
Solved the 'redirects to the webform node' on validation error, along with another issue I was having with passing info about the node with the webform embedded in it.
On that note, it must be time for lunch. :)
Cheers, Jules
Comment #32
nitesh sethia commented#22 is working fine and was able to fix this issue up.
Comment #33
aniket.mohite88 commentedBanense you are a legend.
That was a really great solution, exactly what i was looking for.
Comment #34
skribbz14 commentedClient Side Validation worked great to fix this problem for me.
Comment #35
madanzes commented#22 works for me too. thanks
Comment #36
batandwa commented#22 thumbs up.
Comment #37
dagomar commentedRelated issue on 7.x-4 with patch:
#2158261: Webform block redirects to page by default
Comment #38
truyenle commented#22 work for me also.
Comment #39
shahidbscs commented#22 @banense, Just Awesome
Comment #40
timme77 commented#22 is just perfect!
Comment #41
peterx commentedAdded #22 to the following documentation on Webform in a block.
https://www.drupal.org/node/1447436
Comment #42
谢艳 commentedHere is my code, VERSION: 7.x-3.20
Webform as block staying on page after validation errors and allow no redirect
Comment #43
m1n0 commented#22 Solves the issue, thanks!
Comment #44
aiphes#22 save me after finding the checkbox on
/admin/build/block/configure/webform/client-block-ID#block_settings