• Resolved korg007

    (@gillesgagnon)


    Hi Forminator Support!

    We need to add a link (<a>) in the textarea Default Value field but the html tag gets stripped.

    Any idea as to how we can get a link in in the Default Text of filed of the textarea field?

    We look forward to hearing from you,
    Cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @gillesgagnon

    I hope you’re well today!

    HTML/JS/CSS code is indeed removed from text field values due to sanitization – for security reasons.

    I have asked our developers for advice on workaround and I’m awaiting their feedback.

    I’d appreciate some patience as they deal with a lot of custom tasks on daily basis so their response may be a bit longer than ours here – but we’ll update you here as soon as we got information back form them.

    Kind regards,
    Adam

    Thread Starter korg007

    (@gillesgagnon)

    Sounds good Adam. As you recall, I had posted another support ticket here some weeks back about a similar issue with line breaks being stripped. You had provided a workaround which we implemented. ??

    I hope a solution can be provided as it would lift restrictions in the stylihng of the content for those fields.

    We look forward to hearing from you,

    Cheers!

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @gillesgagnon

    Actually, I just got a response. In this case, however, we can’t “lift restrictions” easily, I’m afraid, so a different workaround can be used.

    You would need to add this code to the site first as MU plugin:

    <?php 
    
    add_filter( 'forminator_field_text_markup', 'wpmudev_formi_render_anchor_textarea', 10, 2 );
    function wpmudev_formi_render_anchor_textarea( $html, $field ) {
        if ( $field['element_id'] == 'textarea-1' ) {
            if ( strpos( $html, '{wpmudev_anchor}' ) !== false ) {
                $html = str_replace( '{wpmudev_anchor}', '<a href="https://mylocal.local/">Here</a>', $html );
            }
        }
        return $html;
    }

    – create an empty file with a .php extension (e.g. forminator-textara-default.php)
    – paste code into it
    – and make two changes in the code

    a) in this line

    if ( $field['element_id'] == 'textarea-1' ) {

    replace textarea-1 if needed with your textarea field ID

    b) and in this line

    $html = str_replace( '{wpmudev_anchor}', '<a href="https://mylocal.local/">Here</a>', $html );

    replace the

    <a href="https://mylocal.local/">Here</a>

    part with your own A tag code.

    – save the file and upload it to the “/wp-content/mu-plugins” folder of your site’s WordPress installation

    Next step is to add following as default value of the textarea field

    {wpmudev_anchor}

    Save the form and that’s it. It will use the link there.

    Kind regards,
    Adam

    Thread Starter korg007

    (@gillesgagnon)

    Thanks Adam. My apologies. After adding to this thread I realized that being “resolved”, it may not get attention. I created the new thread, tried to remove this one but the interface wouldn’t allow me. I tried LOL.

    Thanks for your continued support.

    Thread Starter korg007

    (@gillesgagnon)

    Thanks so much Adam.

    This code will only work if we have a single “a” tag though, right?

    • This reply was modified 1 year, 5 months ago by korg007.
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @gillesgagnon

    Thanks for response!

    With this code you do not actually put the “a” tag in the field directly. Instead you put that {wpmudev_anchor} placeholder in it and it gets replaced by the code.

    The replacement is defined within the code itself.

    The code shared, indeed, uses just a single “a” tag but you can add more links or text, simply by editing this line

    $html = str_replace( '{wpmudev_anchor}', '<a href="https://mylocal.local/">Here</a>', $html );

    For example:

    $html = str_replace( '{wpmudev_anchor}', 'Hi! To learn more <a href="https://mylocal.local/">click here</a> and to join my newsletter, click here: <a href="https://site.com/newsletter/" target="_blank">subscribe</a></p>', $html );

    I believe you get the idea ??

    Note: this is about the “Default value” only. If you also want to allow adding such link on front-end when filling-in the form, you need to switch the textarea field settings to use “rich text” editor.

    Best regards,
    Adam

    Thread Starter korg007

    (@gillesgagnon)

    Hi @wpmudev-support8 , Adam,

    Thanks for the detailed clarification. Yes, that’s what I thought. Unfortunately, we’ll have to forego adding adding that html “a” tag in the Default Value. The workaround is too limiting and too complicated to implement/maintain by the users of the site, being laypeople.

    We can only hope an elegant and simpler solution will be available in the future. For example, allowing some tags or allowing the use of a richer editor for the field.

    Thanks again for your attention to the support thread and for the timely responses. Again, it’s much appreciated.

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @gillesgagnon,

    You are welcome.

    I am now marking this ticket as resolved. Please feel free to open a new ticket if you need any further assistance.

    Kind Regards,
    Nebu John

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How to add a link () in the textara – Default Value’ is closed to new replies.