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?

Comments

perisdr’s picture

Component: Rules Core » Rules Engine

Any 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.

checker’s picture

I have the same problem and will look into that.
Edit:
I don't think the white space comes from rules...

pedrosp’s picture

Component: Rules Engine » Rules Core

I 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]

ekidman’s picture

Project: Rules » Webform Rules
Version: 7.x-2.x-dev » 7.x-1.6
Component: Rules Core » Code

I'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.

checker’s picture

I don't use webform rules and i have this problem too.

ekidman’s picture

Checker, 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

ekidman’s picture

So 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:

 if ($display_element['#value'] !== NULL){
  return drupal_render($display_element);
}

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.

checker’s picture

ekidman, 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.

mjcarter’s picture

One 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)

badrange’s picture

Category: Support request » Bug report
Issue summary: View changes
StatusFileSize
new778 bytes

I'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:

* [data:{component}-value]
Same as [data:{component}-title], but it returns the value instead of the
title.
* [data:{component}-value-html]
This one does exactly the same as [data:{component}-value] with the
difference that its output will be rendered as html.
* [data:{component}-value-raw]
This one does exactly the same as [data:{component}-value] with the
difference to not clean up the value using check_plain(). This is raw user
input so take care if you use this somewhere else.

Attached is a patch that does away with drupal_render and only runs check_plain on the value.

badrange’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
StatusFileSize
new750 bytes

As 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.

badrange’s picture

Status: Active » Needs review
tlthades’s picture

Thank you, badrange, the problem was solved by the patch from #11.
If I have any problems later on, I will write here.

tlthades’s picture

This patch works fine.

badrange’s picture

Should we set it to RTBC?

checker’s picture

I don't use this module or this patch. But I can say you that this patch does not follow drupal coding standards.

badrange’s picture

Attached is a patch that should adhere to the Drupal coding standards. Should we RTBC now?

jsst’s picture

Status: Needs review » Reviewed & tested by the community

This patch should land in a stable release. Note that this also fixes excess whitespace *after* a value: "Dear sir Test ,".

tenamurphy’s picture

#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!

coreteamvn’s picture

There 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

dcamburn’s picture

Is 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.

bisonbleu’s picture

Priority: Normal » Major
Issue tags: +PLEASE COMMIT!

I 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.