I posted a previous support request under a different title and I apparently didn't make myself clear enough about the problem I was experiencing. It had to do with upgrading to the latest version, 6.x-3.6, which had a problem that appeared to be fixed by Webform_PHP, which is not supported.

Since it takes too long to type in the entire explanation, I took MORE time 8-) to make a video explaining the problem. It's 4.5 minutes long and it is here -> www.theloadpost.com/video/WebformPblm/WebformPblm.html

Comments

quicksketch’s picture

Hi Mike, I watched your descriptive video and I don't think my answer is really going to change too much here. I'll try to answer each part of your question in response to your video.

1. Where did the PHP fields go?

The PHP fields are no longer in the 3.x version of the module. It's a feature reduction from the 2.x version of the module. The *only* way to get these fields back in the same location as before is to install the unsupported Webform PHP module.

2. What happened to my existing PHP code?

Your existing PHP code is actually still there, saved in the "webform" database table in the additional_processing and additional_validate columns. However this code is not executed in the 3.x version of the module unless Webform PHP is installed.

3. Why were the additional validation and submission fields removed?

They were removed because of the wildly dangerous potential of executing PHP code in a textarea. See my explanation at #1043088: This project is abandoned, please stop using it.

4. Well if the fields are removed, how am I supposed to execute PHP code when the form is submitted?

You should do any custom coding in a module that will execute the PHP code from there. All code should always belong in a module, as it is easier to debug and much less likely to be exploited (intentionally or accidentally) by an end-user of your site.

An example for your particular use-case would look like the following:

- Make a new directory in sites/all/modules called "webform_extra".
- Make a new text file in sites/all/modules/webform_extra called webform_extra.info. Put this inside of it:

name = Webform Extra
description = Customizations for the Webform module.
core = 6.x
package = Webform
dependencies[] = webform

- Make a new text file in sites/all/modules/webform_extra called webform_extra.module. Put this inside of it:

<?php
/**
 * Implementation of hook_form_alter().
 */
function webform_extra_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'webform_client_form_44') {
    // Simply add the additional validate handler.
    $form['#validate'][] = 'webform_extra_validate_44';

    // Add the submit handler after the existing Webform submit handler,
    // but before the second Webform handler. Pop off the first one and add
    // ours second.
    $first = array_shift($form['#submit']);
    array_unshift($form['#submit'], $first, 'webform_extra_submit_44');
  }
}

/**
 * Validation handler for Webform ID #44.
 */
function webform_extra_validate_44($form, $form_state) {
  global $user;
  if (!isset($user->roles[4])) {
    form_set_error('', t('To delete a truck or load, the trunk/load must belong to your userid and you must be a permanent Member or on a trial basis. Please see the Home page.'));
  }
}

/**
 * Submit handler for Webform ID #44.
 */
function webform_extra_submit_44($form, $form_state) {
  global $user;
  include 'sites/default/files/posttrunkproc.php';
  posttrunkproc("", $user->name, $form_state);
}

- Turn on the new Webform Extra module you've just created.

5. Wow, that is so much extra work than just typing code into a textarea! Can't you just put those fields back in the interface so that I don't have to write a custom module like this?

At some point safety takes precedence over convenience. The removal of the PHP code fields from Webform is part of a broader trend in the Drupal community to make Drupal a safer and mature system. No respectable piece of desktop software would ever give you a textfield for "Enter C++ code here", the same applies to Web software. The ability to execute PHP code in a textfield has been removed from the Drupal 7 version of CCK for example. The "PHP Input Filter" was separated from Filter module and disabled by default in Drupal 6. There's a good chance it will be removed entirely and moved to contrib in D8. The removal of all PHP textareas is an eventuality that the Drupal community will need to adjust to, most likely by education on how to write simple custom modules, like the one I've described here.

ecksley’s picture

I thank you for taking the time to document a potential new module, but I am disappointed that these fields have been removed.

Perhaps there is no place for PHP code in a web software. But respectfully, Drupal is also a web development software, and thus I feel PHP is acceptable if access can be restricted. Certainly you wouldn't allow end users to enter PHP. But isn't that why we have a permissions system? If someone is a trusted user and has the correct permissions, what is the risk?

A good example is the block system's visibility settings. I see that Drupal 7 has created a more robust GUI for filtering blocks. Very good. But I can still imagine a number of reasons why PHP evaluation would be useful, and thankfully is still allowed.

Speaking as a designer, such fields are a stepping stone toward descending into module development, hooks, field API, etc. I'm not sure how many of my ilk would attempt Drupal if knowledge of the aforementioned was needed for every snipped of PHP.

Anyway, I know this isn't a debate. What's done is done. I appreciate your work. Thanks for Webform!

quicksketch’s picture

Status: Active » Fixed

It's still possible to have these fields through another module, but surely you can understand my hesitation around trying to offer any sort of support for such a dangerous and error-prone feature. You can still use Webform PHP (it works fine), it's just that such implementation is completely unsupported for all the reasons I have outlined.

mwease’s picture

ok. i got it, while wiping the tears from my eyes.

thank you for such a lengthy, informative and thorough explanation. i needed that. i had no idea what the security update was for or that those text areas for PHP code had purposely been removed. i believe i read the readme file.

no users of any kind but my one super admin account has any access to anything at all, as far as changing content. i didn't do much the "Drupal way" because i couldn't figure out how. i have tons of PHP code and am not using taxonomy, CCK, views or much else but blocks (with PHP code in THOSE text boxes...?). however, i LOVE webform.

since none of my users can ever change any content and the only textareas into which they can enter data are those presented to them usually via a webform, and whatever they enter gets to my PHP processing code as data in the $form_state array, is there really any risk for my site the 2.x way or using webform php?

quicksketch’s picture

is there really any risk for my site the 2.x way or using webform php?

I'd say the risks are greater sticking with Webform 2.x than using Webform PHP. There is no "inherent" security risk caused by using Webform PHP, it's just not a "best-practice" way to build out a site and is likely to expose your site to security problems if it were misconfigured. Webform 2.x is not receiving further updates so if new problems are found in the future, they likely will not be addressed.

mwease’s picture

but, specifically, if no users but the super admin can change content, which is what i'm doing, i would like to know what the security risk is. how could anyone hurt anything by entering anything in a text box/area webform presents to them (or any way i probably don't see/understand) when that info is simply data to the webform processing? and, aren't blocks, where they take PHP in a text area prone to the same risks?

quicksketch’s picture

Status: Fixed » Closed (fixed)

I'm pretty sure I've already answered the question several times over.

There is no "inherent" security risk caused by using Webform PHP, it's just not a "best-practice" way to build out a site and is likely to expose your site to security problems if it were misconfigured.

mwease’s picture

I just don't understand the specific risks of using 2.x Webform. I don't doubt that they are there. I would really appreciate an example of what they are. I'm thinking and hoping that, the way I'm using it, those risks don't apply and that's why i'm trying to ask the right question.

I guess I also just don't understand what is "dangerous and error-prone" about PHP in text areas for the builder of a site. To allow anyone other than the site builder to do this would probably present problems, but if only the site builder can place PHP code into any particular text area, I don't have the imagination or knowledge of hacking to understand the risk.

Hopefully, I can get the question(s) right this time:

1) What can someone specifically do to screw up my site because of the text areas in 2.x Webform containing PHP code if nobody but me has any access at all to the admin pages of Drupal, especially the text areas in Webform?

2) If nobody but me EVER has access to these text areas, i.e. can change the PHP code there, would upgrading to the current Webform (to stay current) and add Webform PHP (to make it look and act like 2.x) still be "dangerous and error-prone"?

I feel exactly like ecksley does in his post (#2): If the permissions preclude anyone but me from having access to the Webform text areas, what is the risk? I just can't see any risk that way, but I keep asking because there is just a little bit about how browsers and programming and websites work that i don't know...well, maybe a lot. :)

THAT is my question, along with #2 above.

ecksley’s picture

MWease, Inconvenient as this feature reduction is, you have to admit the module is actually cleaner now. Those fields always seemed a little "dangerous and error-prone" to me. I can only image the tital wave of misuse and support requests they prompted. I suspect that is the driving force behind the decision to remove them.

Regarding PHP fields... I can't imagine Drupal without them, but I think I will never have to. If that day comes you and I can form an armed rebellion. :) To me, this move has more to do with the sustainability of the Webform project... which I am thankful for.

jakew’s picture

Why get rid of php fields? That's why Drupal has access control. A user with "administer content" access could destroy a site's content just as easily.

mwease’s picture

i have already agreed with you, jakew.

i tried to reply to ecksley's last post last night, but was logged off every time i logged in. seems like i can stay here a little while tonight.

ecksley, if "cleaner" means the absence of those two text areas for php code, then i say 'yeah, something's gone'. it's kinda your favorite couch being thrown out when you weren't there. if you mean the code is cleaner, i have no idea. i've never looked at it.

in addition, nobody answered my question about blocks in particular. they have text areas for code, as well as pages. i'm guessing that stories and whatever other nodes there are also employ text areas. they need to go, also, i guess. of course, i have no idea how we can associate any php code with those nodes, except, as quicksketch displays, we'll have to have our own modules written in order to use any of them.

quicksketch hasn't responded to my last. could either of you folks do it? if it's true, as both of you have said, that permissions are there to protect all of these text areas, then my answer is what i thought. however, i can't rely on myself, because my drupal knowledge is much less than most because i haven't used the power of drupal much.

the question is: if NOBODY has ANY access to any admin pages, especially those of Webform, then is my site's security compromised if i use the latest webform module (to stay up to date) AND the very dangerous and error-prone module, Webform PHP, which was obviously written to put the text areas back into the webform, and does, but will apparently not be maintained and is not recommended?

ecksley’s picture

mwease, I hear you about permissions. Obviously, that was my point earlier. I don't think it is about that as much as it is about preventing user error.

I can't speak for quicksketch, but I interpret his response to mean that he has removed your favorite couch from the module because he is tired of people getting hurt on it and blaming him. While you and I may have used them with success, you have to admit those fields required a lot of explanation. I imagine it was pretty easy for well intentioned admins to screw up. So I think he is saying you are free to use it at your own risk with the new module, but he doesn't want to be bothered every time a new person tries to recline the couch and puts a hole in the floor. Anyway, that is my take.

I didn't mean to code is cleaner. No idea about that actually. I meant cleaner as in more easy to intuit. No more, 'what the hell do these do?' fields.

mwease’s picture

ecksley, yes, permissions was your first point and it was my first point of confusion, since i couldn't figure out what the security problem was. I agree with that and that's why i asked the questions i did.

You may be exactly right about quicksketch's motivations. however, his explanations did not indicate that. i suppose that could be a form of political correctness in action.

I don't think i have to admit at all that the PHP fields require explanation. as lacking in knowledge of drupal, PHP and HTML as i was when i decided that using Webform would save me learning more about HTML than i needed/wanted to at the time, i decided to go with webform because i understood what was required. as ignorant was i was, those fields were much more understandable to me than the vast majority of drupal or contributed modules at which i'd looked.

thank you for continuing my analogy about the couch!

i disagree with your point that, without the PHP text areas, Webform is more intuitive. without them, my first question would have been, way back and, obviously now, "ok. i have defined a form with fields by which users can provide me the data i need, but how the hell do i process what they've entered on the form?" without the fields and, more importantly, their labels, "Additional Validation" and "Additional Processing", which, to me, explained exactly what should be put into them, nobody could possibly have a clue about what to do with the form and, therefore, be very interested in bothering with Webform. i have learned a substantial amount of HTML since i started my site and, because of this change to Webform, i have almost decided to change all of my 24 or so webforms to one HTML form and one PHP file to "validate" and "process" it each. it would actually save the number of code files i keep on my PC, i could put more than one input field per line, more than one button, and i wouldn't need the Webform module.

AND, not that i'm demanding anything, i STILL haven't received a definitive answer to my original question. you have implied it, but i am still too afraid to make ANY assumptions at all.

in addition, nobody has responded to my comments/questions about, as i understand it, other drupal nodes, such as pages, blocks, etc., that employ the exact same text areas for PHP/HTML code being the same security risk. i'm assuming that your "take" on quicksketch's motivations are correct. otherwise, most of drupal would have to be overhauled in the same way as Webform to take away those dangerous and error-prone text areas that allow PHP code to be entered.

druth’s picture

Thanks for providing the code examples quicksketch. Also, thanks for removing these fields, now we don't have to create a form alters to remove them :)

InterJinn’s picture

I have to say I find the arguments in favour of removing this functionality to be very weak. Content, blocks, and various other modules all allow the PHP input filter to perform PHP processing. For some reason you find the filter/permissions functionality that's been built into Drupal since probably forever (I started with Drupal 4) to no longer suit your needs and you call it insecure. If that is true you've made Drupal no more secure since this functionality continues to exist everywhere else. Claiming anyone can use the unsupported unmaintained Webform PHP module is a cop out. Why not at the very least put the functionality back in and make it a setting in settings.php where I imagine you could expect anyone placing a setting there to know what they are doing since you appear to be afraid of noobs hammering their own toes. Anyways, I feel the need to call bullshit on this change and the arguments in favour of it.

InterJinn’s picture

I was a bit hasty on that last comment... I didn't realize the Webform PHP module works in conjunction with Webform, That's at least a good alternative solution similar to my suggestion of a settings.php config entry. I still don't see the point in removing this functionality, since anyone with the PHP input permission can still wreak havoc with the site via the description confirmation page description box which is where I was about to move the post processing funcitonality. But hey, it is your module after all. I probably wouldn't care so much about this change if there had been a transition period... say Webform 3 indicating that it would be removed and then a year later Webform 4 having it removed. But I'm on a deadline right now, going back and changing all our webforms is not something I can do right away.

Cheers,
Rob.

mwease’s picture

Rob, i don't think you were hasty at all with your first comment. your comment in your first post was right on: we're supposed to use a module that is not maintained and 'dangerous' if we want things the way they were. if it's not maintained, do we have any idea of whether or not the next release of webform will be compatible with webform php? i would say not. i'm glad we agree on the fact that so many OTHER modules in drupal allow exactly the same thing as was taken away from webform makes the 'security' argument moot.

can you answer my question. apparently, i'm not going to get it from nathan. i'll repeat it:

"the question is: if NOBODY has ANY access to any admin pages, especially those of Webform, then is my site's security compromised if i use the latest webform module (to stay up to date) AND the very dangerous and error-prone module, Webform PHP, which was obviously written to put the text areas back into the webform, and does, but will apparently not be maintained and is not recommended?"

and, as and addition to that, the question above about the lack of maintenance on webform php.

Cyberwolf’s picture

Of course it's dangerous to allow third parties to inject PHP code into your system. But in an environment with limited access for content managers and full access for developers I don't see the problem. PHP filters in CCK text fields, Views header and footer, Rules actions that execute arbitrary PHP code, ... are also vulnerable if not used with care. They are potentially dangerous, but does that justify to completely abandon those features? I would say NO.

LEternity’s picture

Title: Webform Additional Validation & Additional Processing disappear after upgrade » Webform Advanced Settings (Additional Validation & Additional Processing) disappear after upgrade

Changed title for better googleability.

quicksketch’s picture

I probably wouldn't care so much about this change if there had been a transition period... say Webform 3 indicating that it would be removed and then a year later Webform 4 having it removed.

Webform 3 was under development for over two years and went through dozens of pre-releases publicly available all with the PHP functionality removed. This wasn't exactly an "all at once" decision.

In any case, I won't be adding a PHP textarea back into Webform with any amount of lobbying. You can install Webform PHP if you want this functionality.

bwoods’s picture

For what it's worth, I had never created a completely new module until adding webform_extra today. I added the validation and processing I needed for one form in this manner, and it took me about 20 minutes. The example outlined in #1 is pretty simple. Thanks for creating and maintaining this module!

akki123’s picture

Hi quicksketch

I am trying to set up such custom module for 7.x but without any success.

I have a web form with send copy to user Checkbox, if user do not tick checkbox , no email copy will be sent to sent to user. I am trying to achieve this functionality. Please give some pointer.

Thanks