0

I have a webform in which I've developed a custom module to add a value to a hidden element based on inputs received by the person submitting the form. I also have an email handler specified that sends the submitted values, including the value assigned to the hidden field, to me as the site administrator. I'm using the Swift Mailer to get uploaded files delivered as email attachments. I have the email configured to be sent as plain text.

This all seems to be working fine, with the exception that quote characters (") that my module adds to the value of my hidden field and other characters that were typed into a text field are being converted by something into HTML entities ("). I've checked the value of the fields via debug logging and things look fine when the field values is saved. What might be converting the quote characters, and what can I do to avoid the conversion?

My code:

/**
 * Form submission handler.
 *
 * @WebformHandler(
 *   id = "register_form_handler",
 *   label = @Translation("Vehicle Registration"),
 *   category = @Translation("Form Handler"),
 *   description = @Translation("Reformat vehicle registration values"),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
 */
class RegisterWebformHandler extends WebformHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
    // Get an array of the values from the submission.
    $values = $webform_submission->getData();

...

    // Capture owner data in CSV format for database entry.
    $csv_temp = '"' . $values['owner_name'] . '",'
      . $values['email_address'] . ","
      . '"' . $values['telephone_number'] . '",'
      . '"' . $values['street_address'] . '",'
      . '"' . $values['city'] . '",'
      . '"' . $values['zip_postal_code'] . '",'
      . '"' . $values['state_province'] . '",'
      . '"' . $values['country'] . '",,'
      . $values['vehicle_identification_number'];
    $values['owner_entry_csv'] = $csv_temp;

...

    // Set submission data.
    $webform_submission->setData($values);
    return true;
 }
}
  • quote characters (") that my module adds The cause maybe here. Can you edit your question and put up the code that you're using to do this? – No Sssweat Apr 16 at 23:08
  • I don't think this is the case. I'm having the same issue with quotes and apostrophes that are entered in text fields by the person filling out the form. My code doesn't touch those fields. – Scott Hollenbeck Apr 17 at 9:55
  • In /admin/config/system/mailsystem what formatter are you using? If you're using Sendgrid Integration try using a diff one. I noticed Sendgrid Integration puts it in <b>test2</b><br />&quot;cool&quot;<br /><br /> while others do not. Perhaps your recipient's mail host isn't capable of translating those &quot's. – No Sssweat Apr 20 at 8:22
  • I am (was) using the Swift Mailer formatter. I tried using the Default PHP Mailer formatter, and sure enough the problem went away. This is interesting (and perhaps a Swift Mailer bug) because I have Swift Mailer configured to use Plain Text message formatting and "Respect provided e-mail format" is unchecked. Anyway, thanks for the tip! – Scott Hollenbeck Apr 20 at 12:47
  • The issue is with the recipients e-mail host/provider not able to transform &quot. Bug is on the recipients e-mail side. On my e-mail it looked fine, I was only able to tell the difference by looking at the source code. – No Sssweat Apr 20 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.