dongatuna Posted January 22, 2015 Share Posted January 22, 2015 Would like to create a function for text input and text area. I have the following code that generates the text field but it isn't sticky. <?php function create_text_field ($label, $name, $value){ echo '<label>'.$label .': </label>'; echo '<input type = "text" name ="'.$name.'" value = "'.$value.'"'; if(isset($_POST[$name])&&($_POST[$name]==$value)){ echo $_POST[$name]; } echo '/><br><br>'; } ?> The data doesn't stick... Link to comment Share on other sites More sharing options...
HartleySan Posted January 22, 2015 Share Posted January 22, 2015 Hello and welcome to the forums. The value you set for the value attribute of the input element is what will actually be made "sticky". In other words, in your code above, the value of the $value variable will be made sticky. Make sense? Link to comment Share on other sites More sharing options...
dongatuna Posted January 22, 2015 Author Share Posted January 22, 2015 Not quite yet but close. The value attribute code is inside <?php?> tags. I want to create a function that creates text field that is sticky I cannot place a php tag in the value attribute (since is part of function statements) Please comment Link to comment Share on other sites More sharing options...
HartleySan Posted January 22, 2015 Share Posted January 22, 2015 You mean you want this? <?php function create_text_field($label, $name, $value) { echo '<label>' . $label . '</label>'; echo '<input type="text" name="' . $name . '" value="' . $value . '" />'; echo '<br><br>'; } ?> Also, you're mixing HTML and XHTML and your br tags are not semantic. Link to comment Share on other sites More sharing options...
Recommended Posts