Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've got some code to create a new node which I'm trying to test, but it never gets invoked. I know this as I've put a breakpoint at the start of the function I'm calling from my code (node_save), but it never breaks there, even though this technique works with eval'd PHP code in other modules.
I've also tried it in additional validation, but it doesn't get called from there either.
Interestingly, it must be being parsed though because if a miss a semicolon or something, I get the usual PHP error reported.
Thanks in advance for your help.
Comments
Comment #1
quicksketchI don't quite understand this request. What are you trying to accomplish and how are you trying to do it? I generally don't provide support on how to write code in the Webform issue queue.
Comment #2
akarabin CreditAttribution: akarabin commentedI've got the same problem and didn't find the way to solve it, any PHP code that I'm using into de Additional processing, even an echo "hello world" doesn't work, altough I am pretty sure that redirection or Confirmation Message at least are working, I've already check permissions for this module to work for any user and still having no processing. I'm using exactly the same version. Thanks
Comment #3
quicksketchAny call to echo or print won't show up, because the code is executed within an eval() command and any output is discarded. If you want to print out debugging messages, use the dsm() function provided by devel module.
Comment #4
akarabin CreditAttribution: akarabin commentedThanks but not using devel module, but any operation into my php code it is not been evaluated, I've used the drupal_set_message and it didn't work. Also I'm using the drupal_write_record() function to insert a new register and it doesn't work either.
Comment #5
brack11 CreditAttribution: brack11 commentedthe same here: no code is working, as last resort tried $node->webform['confirmation'] = 'http://google.com'; with no luck
Comment #6
keva CreditAttribution: keva commentedneither
$node->webform['confirmation']
nor$node->webform['redirect_url']
result in a redirectComment #7
quicksketchI found the reason for this is because Webform PHP loads a copy of the $node variable for you to work with, rather than modifying the one Webform works with directly. This results in changes to the $node object not having any effect.
The code from webform_php.module that does this execution:
However, the code IS being executed just fine, but changes to the $node object have no effect.
Comment #8
roball CreditAttribution: roball commentedComment #9
catofcheshir CreditAttribution: catofcheshir commentedSo is there a way to set redirect by this module?
Comment #10
jennypanighetti CreditAttribution: jennypanighetti commentedSo, what DOES this module do, then? I need to set a conditional redirect in the node and add additional_emails in the node. With additional processing no longer supported by webform, how in the world do I add additional_emails now???
Comment #11
goodwillhinton CreditAttribution: goodwillhinton commentedAny luck in resolving this problem? I am seeing the same thing.
Thanks!
Comment #12
primerdp CreditAttribution: primerdp commentedHi - is there a possible workaround for this available? I am in dire need :)
Comment #13
primerdp CreditAttribution: primerdp commentedSo, sincerest apologies in advance if I break community guidelines here. This is a hack. I thought I would share it for those of you who need things *now*, but do not put this in a production system.
I know very little about Drupal, as this is my first day using it. So, for now, here's something that got it working for me:
Anyway, this could absolutely break everything as I did zero unit tests (or anything, for that matter).
Comment #14
goodwillhinton CreditAttribution: goodwillhinton commentedprimerdp: Thanks so much for that quick hack. That does seem to work. I'll do some testing and let you know if I find anything else.
Comment #15
kruser CreditAttribution: kruser commentedsubscribe
Comment #16
kruser CreditAttribution: kruser commentedIf you just want to redirect, I found that the drupal_goto(); function works...
http://api.drupal.org/api/function/drupal_goto
Comment #17
jfinkel CreditAttribution: jfinkel commentedPerfect. Thanks.
Comment #18
roball CreditAttribution: roball commented(pls ignore)
Comment #19
no2e CreditAttribution: no2e commentedsubscribing
Comment #20
Anonymous (not verified) CreditAttribution: Anonymous commentedUsing drupal_goto() prevents the webform from showing as submitted. It doesn't show up under the submissions list or send an email out... it's like the submission didn't even happen.
Using this code:
It redirects perfectly though.
Comment #21
FooZee CreditAttribution: FooZee commentedI've found a solution, which is not supposed to be the normal behaviour, but worked fine for me, I found out that using " echo " ... u can just output whatever u want ! .... if u directly used something like
echo "You have been Registered, successfully!"
it won't appear as good though!... but think of using firebug to put this in the main content-area of ur theme ! (i.e. make echo output a static HTML page exactly similar to your website, and as I've mentioned, u can always get that code very easily with a tool like firebug :DComment #22
quicksketchI wouldn't suggest the approach in #21, since if you print to the page it may prevent further processing by Drupal during the form submission. If you want to print content to the page, I suggest theming the confirmation page for the webform, as described in THEMING.txt included with Webform.
Comment #23
ainz CreditAttribution: ainz commentedThis worked for me: http://www.vilepickle.com/blog/2010/11/11/0086-redirect-webform-submissi...
It looks confusing at first but if you look at it, its quite simple:
Firstly the code he uses in Additional Processing to some extent adds to the confusion:
Just use whatever if statement resolves TRUE for your particular webform based on your fieldnames. I used:
Dont forget if you changed the name of the variable being passed you have to change it in the php code on the submitted page as well. Values are being submitted to the database without any problem
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedThat's actually my blog post :P
The first if statement is checking a field on the first page of the Webform (the one I really want to check) and also if a field is defined on the last page of the Webform. The reason I did this is because I used it on a multi-page Webform and it would perform the validation from the snippet when I hit "next page" and not just the "submit" button on the final page. I had to do an additional check to make sure the field on the last page was defined. Unsure if it's a bug but it seemed like something that shouldn't be happening.
Comment #25
ainz CreditAttribution: ainz commented:) Nice...small "world". Now I get to thank you! I was trying to do it on your blog but it wasn't immediately obvious where I should create an account (or maybe I didn't try hard enough :S. I had thanking you on my TODO list though. This was a life saver. Had to look at it for a while but it worked perfectly once I figured out what was happening. I thought the php page as a processor was genius! I understand what you were doing now that you explained it.
I really need to get comfortable with mod development so I can help with issues like this but thanks again!
Comment #26
cashbrown CreditAttribution: cashbrown commentedBig ups @ vilePickle for the fix. I made one small change: rather than create a "formredirect" page like you said in your instructions, I threw together a small "formredirect" module with the drupal_goto() and other code I needed. That way I can do this without enabling PHP filter :)
Thanks again!
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedActually another caveat of the drupal_goto in a separate page that I found was that if you have search enabled on your website your cron will not run properly. It encounters the drupal_goto and actually executes it, redirecting away from your cron run. Apparently this was a big issue when I googled it and it hasn't been fixed in years. I fixed it by disabling search on the site I use this on because it wasn't needed (there were other workarounds that... didn't work for me). Cashbrown's module approach is probably a much better solution... you might look into putting that up for the public on drupal.org.
Comment #28
HMahoney CreditAttribution: HMahoney commentedI have been trying to solve this problem for several days. I'd really like to see Cashbrown's approach. Please?
Comment #29
ainz CreditAttribution: ainz commentedI second cashbrown's module.
Comment #30
cashbrown CreditAttribution: cashbrown commentedI'll clean up what I have and try to get it posted in the next few days. What I put together was very specific for my purposes; passing information to an authorize.net gateway. At the moment it's barely cobbled together :)
Comment #31
ainz CreditAttribution: ainz commentedThis might be obvious but I had to ask. What is the downside to referring directly to the actual node instead of loading a copy of it?
Comment #32
quicksketchI'm not sure, but I may have done this specifically done this so that you couldn't break your webform by doing something like
$node = node_load($other_nid);
, which had caused some support requests in the past.Really the big reason right now is because I don't want to have to modify Webform in order to support this module which I don't really want to exist anyway.
Comment #33
phacts CreditAttribution: phacts commentedI have found a way to solve this problem using an approach that I think quicksketch intended for the webform_php module. Basically, open up the module and copy the hook_form_alter code to your own module, then do this:
I use this to alter the email sendto address in the $form['#node'] object, and it works. Enjoy, and good luck!
Comment #34
quicksketch#1043088: This project is abandoned, please stop using it
Note that any API changes needed to dynamically change the submission URL or other settings via an API change would still be considered, but if you're writing a custom module like you should be anyway, you can just set $form_state['redirect'] anyway.