Search code examples
phpwordpresstextboxhtmlspecialchars

How do i implement htmlspecialchars for a textbox value?


Hello i'm currently using a table to input values into a custom meta field. I have a text box called episode title. My problem here is that if the characters ' " are added in the field then everything goes in to chaos. I want to use the htmlspecialchars to input the values as &quot and &#039 instead of ' ". the below code does not work to covert the characters. Can anyone please help?

    <p>
      <input type="text" name="episode_title[]" id="episode_title[]" value="<?php echo ($_POST['episode_title']); ?>" class="title regular-text" style="width: 98%" />
      <span class="description"><?php _e('Title of The Episode.'); ?></span>
    </p>    

Solution

  • add this to the htmlspecialchars call: ENT_QUOTES like so:

    <?php echo htmlspecialchars($_POST['episode_title'], ENT_QUOTES); ?>
    

    This will enable changing of both the " and the ' quotes