Teldosh Posted May 1, 2013 Share Posted May 1, 2013 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 More sharing options...
Psycho Posted May 1, 2013 Share Posted May 1, 2013 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}'> "; } Link to comment https://forums.phpfreaks.com/topic/277511-html-special-chars-sticky-textfield/#findComment-1427614 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.