Jump to content

HTML special chars & sticky textfield


Teldosh

Recommended Posts

Hi Guys, Can anyone help with a little problem that I cannot solve ?

I am displaying some textfields in a for loop.
Firstly I need to include htmlspecialchars and make each textfield withing loop sticky.

 

for ($i=1; $i<=$num; $i++)      {
        echo '<input type="text" name="opt_'.$i.')"> '; 
        }

 

This is what I have tried for the specialchars . It did not work.

 

for ($i=1; $i<=$num; $i++){
         echo htmlspecialchars( '<input type="text" name="opt_'.$t.')"> ';    
        }

 

Any help or advice would be great

Link to comment
https://forums.phpfreaks.com/topic/277511-html-special-chars-sticky-textfield/
Share on other sites

You only want to use htmlspecialchars() on the VALUES

for ($i=1; $i<=$num; $i++)
{
    $fieldName = "opt_{$t}";
    $fieldValue = isset($_POST[$fieldName]) ? htmlspecialchars(trim($_POST[$fieldName])) : '';
    echo "<input type='text' name='{$fieldName}' value='{$fieldValue}'> ";    
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.