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 Quote 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 (edited) 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}'> "; } Edited May 1, 2013 by Psycho Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.