• Resolved tgilber007

    (@tgilber007)


    I try to update the custom field with a Tag
    <a href="{url-1}">view</a> but it update only the (view) string in custom field data

    https://prnt.sc/6FbAZk0VFm25

    How to update with this <a href="{url-1}">view</a>

    Thanks in advance

    • This topic was modified 2 years, 8 months ago by tgilber007.
    • This topic was modified 2 years, 8 months ago by tgilber007.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @tgilber007 !

    Hope you’re doing well today!

    Due to security precautions, HTML can’t be used in the custom fields. This would potentially open a serious security hole where someone could add a <script> instead and run any code on your site. We prevent this from happening by removing any HTML tags from the data.

    You can do this in a different and secure way though:
    – set the value to just {url-1}
    – on the page itself display the link, for example like this:

    <a href="<?php echo get_post_meta($post_id, 'custom', true); ?>">view</a>

    You can also create a custom shortcode to display this link from any builder:

    add_shortcode('my_view_link', function($atts, $content) {
      global $post;
      return '<a href="' . get_post_meta($post->ID, 'custom', true) . '">view</a>';
    });

    And then you can place [my_view_link] in the content where you want to display it.

    Best regards,
    Pawel

    Thread Starter tgilber007

    (@tgilber007)

    Thank you for a suggestion, By surfing online i find the below method and it’s work well.

    1. But i have one doubt if this code is secure for use or not.
    2. How to apply this code only for form with id (342).

    Thanks in advance

    add_action( 'forminator_post_data_field_post_saved', function($post_id, $field, $data){    
      $the_post = array(
            'ID'           => $post_id, //the ID of the Post
            'meta_input' => array(
                'custom' => '<a href="'.$_POST['url-1'] .'">view</a>'
       )
        );
      wp_update_post( $the_post );
    }, 10, 3);
    • This reply was modified 2 years, 8 months ago by tgilber007.

    Hello @tgilber007 !

    Hope you’re doing well today!

    You can modify the code like this:

    add_action( 'forminator_post_data_field_post_saved', function($post_id, $field, $data){    
      if($_POST['form_id'] == 342) {
        $the_post = array(
            'ID'           => $post_id, //the ID of the Post
            'meta_input' => array(
                'custom' => '<a href="'.$_POST['url-1'] .'">view</a>'
           )
        );
        wp_update_post( $the_post );
      }
    }, 10, 3);

    I’ve just tested it on my test form and it worked as expected.

    Best regards,
    Pawel

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Tag in Custom Fields’ is closed to new replies.