RensTillmann / super-forms

18 stars 14 forks source link

Zapier plugin double-escapes quotes #55

Closed newz2000 closed 2 years ago

newz2000 commented 2 years ago

Hello, thanks for the great plugins. I have purchased from Envato Elements and it is very comprehensive. I am using the Zapier plugin to submit the data from forms and the end result has an extra \ before every single quote and two extra \ before every double quote.

For example, I used Webhook.site to test the output and you'll see in the value and label fields, the raw data includes an extra slash or two.

  {
  "files": [],
  "data": {
    "hidden_form_id": {
      "name": "hidden_form_id",
      "value": "77576",
      "type": "form_id"
    },
    "TenantNames": {
      "name": "TenantNames",
      "value": "Tenant\\'s Name",
      "label": "Tenant\\'s Names",
      "type": "var"
    },
    "Landlord": {
      "name": "Landlord",
      "value": "Landlord\\'s \\\"name\\\"",
      "label": "Landlord:",
      "type": "var"
    },

I looked through the code but I cannot find where the data is escaped at, so I do not know where to look to suggest a fix.

Please let me know if I can help test it further.

I am using the latest Wordpress with PHP 7.4.3 and nginx + PHP-fpm on Ubuntu 20.04.

newz2000 commented 2 years ago

I found a solution: Wordpress apparently is known to aggressively add slashes to GPC variables so it provides a stripslashes_deep() function. I tested it and this worked (super-forms-zapier.php):

            if( !empty($settings['zapier_enable']) ) {
                $url = $settings['zapier_webhook'];
                if(isset($settings['zapier_exclude_settings']) && $settings['zapier_exclude_settings']=='true'){
                    $body = json_encode(
                        array(
                            'files'=>$files,
                            'data'=>stripslashes_deep($data)
                        )
                    );
                }else{
                    $body = json_encode(
                        array(
                            'files'=>$files,
                            'data'=>stripslashes_deep($data),
                            'settings'=>$settings
                        )
                    );
                }
RensTillmann commented 2 years ago

Hi, thanks, this is now fixed in the latest version of the Add-on.