I have created a webform asking the user for some information. I have set up Rules so when a webform is submitted, the values that the user has entered are written to his profile. That way his profile information is always updated based on his latest webform submission.
After submitting the form I noticed that all of my fields have a white space character in the beginning. Can't figure out why this is happening. I am certainly not adding any white space when submitting the values.
I am using:
Webform Patched 7.x-3.15 (supports tokens)
Webform Rules 7.x-1.2
Rules 7.x-2.0+15-dev
All of my fields are text fields besides the e-mail field.
For the e-mail field I get an error:
Unable to modify data "user:mail": Invalid data value given. Be sure it matches the required data type and format.
Probably because of the white space in front? I don't know if this could be caused by the patched version of webform that supports tokens. I am using the tokens only for retrieving information from the user profile and displaying it as default values in the form fields, so the user won't have to fill them in if the information is up to date. So tokens don't have to do anything with the "writing".
Here's an export of my ruleset.
{ "rules_whitepaper_download" : {
"LABEL" : "Whitepaper Download",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "webform_rules" ],
"ON" : [ "webform_rules_submit" ],
"DO" : [
{ "data_set" : { "data" : [ "user:field-real-name" ], "value" : "[data:real_name-value]" } },
{ "data_set" : { "data" : [ "user:field-surname" ], "value" : "[data:surname-value]" } },
{ "data_set" : { "data" : [ "user:field-company-name" ], "value" : "[data:company_name-value]" } },
{ "data_set" : { "data" : [ "user:mail" ], "value" : "[data:e_mail-value]" } },
{ "data_set" : { "data" : [ "user:field-phone" ], "value" : "[data:phone-value]" } },
{ "data_set" : { "data" : [ "user:field-fax" ], "value" : "[data:fax-value]" } },
{ "data_set" : { "data" : [ "user:field-address" ], "value" : "[data:address-value]" } },
{ "data_set" : { "data" : [ "user:field-postcode" ], "value" : "[data:postcode-value]" } },
{ "data_set" : { "data" : [ "user:field-city" ], "value" : "[data:city-value]" } },
{ "data_set" : { "data" : [ "user:field-county" ], "value" : "[data:county-value]" } }
]
}
}Am I missing something?
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | webform_rules-unwanted_white_space_with_values-1421174-17.patch | 773 bytes | badrange |
Comments
Comment #1
perisdr commentedAny ideas? Could it be possible that the other modules are responsible for this problem? I am a begginer in Drupal so I need some help on where to start looking for what causes this bug.
Comment #2
checker commentedI have the same problem and will look into that.
Edit:
I don't think the white space comes from rules...
Comment #3
pedrospI had a similar problem with webform rules and I used the -raw value instead to make it work.
I mean [data:surname-value] should be [data:surname-value-raw]
Comment #4
ekidman commentedI'm also having this issue, and the solution of using the raw value (as mentioned in #3) works for most cases, but not all. It doesn't work on fields where a file is uploaded, as the raw value uses the fid instead of the actual file name/path. The issue is, when using the normal -value, it inserts an extra space in front of the value, and an extra 2 spaces when there is no value. This is giving me issues in views when I'm trying to hide empty fields, but the fields that get 2 spaces aren't seen as empty.
Is there any solution to this problem? Where are these spaces coming from??
I moved this issue to Webform Rules, as I suspect it has more to do with that than Rules itself.
Comment #5
checker commentedI don't use webform rules and i have this problem too.
Comment #6
ekidman commentedChecker, can you please describe when you're seeing this issue? I'd like to narrow it down to a specific module and/or case. I'm only seeing this issue when using tokens supplied by Webform Rules
And I forgot to add this to my initial post, but the modules I'm using are:
Rules 7.x-2.5
Webform 7.x-4.0-beta1
Webform Rules 7.x-1.6
Comment #7
ekidman commentedSo I dug a bit deeper and have a partial resolution to my issue, in case others need help. I traced it down to the webform_rules_render_component function in webform_rules.module. When I looked at the values with devel right before the end of this function, blank values are set to NULL, as expected. However, when they run through the drupal_render function, or some point thereafter, the spaces are added. I simply changed the end of the webform_rules_render _component (line 335) function to say:
so that the NULL values stay NULL. This effectively gets rid of the 2 blank spaces when a value is empty. It doesn't fix the issue of the single blank space before an actual value that passes through, but that issue isn't affecting me, so I stopped there.
If there is a more logical way to fix this issue, or a way to fix both issues at once, please let me know.
Comment #8
checker commentedekidman, sorry but my first post on "June 12, 2012 at 3:48pm" is a little bit old. So maybe i can't say if the problem still exists for me but i used rules in conjunction with phpmailer and no webform stuff.
Comment #9
mjcarter commentedOne option for tackling issues like this is the rules_data_transforms module. This adds an action to trim whitespace from variables (and a lot more stuff)
Comment #10
badrange commentedI've been fiddling a bit with this issue in the debugger. In our case we are using webform_rules together with a SOAP service, sending SOAP requests to an external API.
The client notified us that there was redundant whitespace around the fields coming into their CRM system. This whitespace is added by the drupal_render() function call in webform_rules_render_component().
A solution could be to switch to value-raw instead of value, but that would cause us sending possible malicious data on to the client.
In my understanding, it doesn't make sense to call drupal_render() for value tokens, since this is supposed to be text content and not html, at least if I read the README.txt correctly:
Attached is a patch that does away with drupal_render and only runs check_plain on the value.
Comment #11
badrange commentedAs mentioned in the previous comment, our use case is that we are using webform_rules to send data via a SOAP request to an external API.
After applying the patch, I noticed that we were sending the form ids for taxonomies instead of the value (form keys instead of value). I am on thin ice regarding this module's expected behaviour, but I suppose you would use value-raw for the taxonomies if you wanted the form key and not the value.
The attached new patch should give you the taxonomy terms instead of their id numbers.
Comment #12
badrange commentedComment #13
tlthades commentedThank you, badrange, the problem was solved by the patch from #11.
If I have any problems later on, I will write here.
Comment #14
tlthades commentedThis patch works fine.
Comment #15
badrange commentedShould we set it to RTBC?
Comment #16
checker commentedI don't use this module or this patch. But I can say you that this patch does not follow drupal coding standards.
Comment #17
badrange commentedAttached is a patch that should adhere to the Drupal coding standards. Should we RTBC now?
Comment #18
jsst commentedThis patch should land in a stable release. Note that this also fixes excess whitespace *after* a value: "Dear sir Test ,".
Comment #19
tenamurphy commented#17 patch works for me. Thanks badrange!
I'm using webform_rules-7.x-1.6 with a Rule to create a new node entity after a webform is submitted, then set a data value on a bunch of text fields. Every field was getting the leading blank. After the patch, no more leading blanks!
Comment #20
coreteamvn commentedThere is also this handy module that trims the white space (first trim the data:email-value and then set the data value). It also provides a couple of other neat helper functions. I had the same issue with the white space when setting a title and this works too.
https://www.drupal.org/project/rules_data_transforms
Comment #21
dcamburn commentedIs there a reason this hasn't been added yet? The patch in 17 works great and was made 4 years ago, but the problem still exists. I'd rather not have to use a module that isn't covered by Drupal's security policy if possible and I'd like to know that when I update Webform Rules (if it ever gets an update) I won't be breaking the white space issue again.
Comment #22
bisonbleu commentedI second @dcamburn's request, «please» commit patch from #17 at least in the dev release and if possible in the a new stable release. I just wasted 3 to 4 hours trying to figure what was wrong with a token that would not set a data value in a select field.