• Resolved Mattia

    (@albazeus)


    Hello, I’m following the ‘Accessing user input data’ cookbook to manipulate the email body.
    In the form there’s a textarea called ‘notes’, to access this field I do:
    $pdsub = $submission->get_posted_data();
    $notes = $pdsub[‘notes’];
    $mail[‘body’] .= <<<EOF
    <tr>
    <td>Notes:</td>
    <td>Note: $notes</td>
    </tr>
    EOF;

    $contact_form->set_properties(array(‘mail_2’ => $mail));

    If I print mail[‘body’] the are no html tags beside the ones I add.
    When I receive the email, I see many <p> and <br> tags added inside my ‘notes’ field.

    Where are these html tags added? Is there a way to prevent it?

    I hope what I wrote was clear, English is not my mother tongue.
    Thanks

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Ciao!
    I think because it’s text field and in order to maintain formatting the function wpautop is used (so when a user adds multiple line breaks at the end of the textfield those are transformed into <br> tags).

    if you want to remove multiple <br/> tags you can use
    $notes= preg_replace('#<br\ ?\/?>(\s*<br\ ?\/?>)+#', '<br/>', $notes);

    Thread Starter Mattia

    (@albazeus)

    Thank you for your answer.

    I will try it this evening but I’m not optimistic.
    I already tried with this:
    $notes = strip_tags($pdsub['notes']);

    and if I print $notes I see no <p> or <br> tags but they are present in the mail I receive.
    I think they are added later. But I don’t know where. Anyway I’ll try your solution.

    My problem are the <p> tags. The mail generated by this form is sent to a software that discards everything after the first <p>. I know this is stupid and I already opened a ticket.
    But I was wondering if I can solve this on my side because at the moment, if an user inputs some empty lines in the textarea, the text is cut.

    Thanks

    • This reply was modified 3 years, 7 months ago by Mattia.

    probably are “\r\n” and not “br”, try to remove duplicates

    Thread Starter Mattia

    (@albazeus)

    Thanks, I solved using this:
    $notes = str_replace("\r\n", ' ', $pdsub['notes']);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘who adds these html tags?’ is closed to new replies.