lfernando Posted August 27, 2010 Share Posted August 27, 2010 Hi there! I am wondering if anyone knows how to handle strings that contain form fields, so when the form is submitted the fields inside the string are updated. For example say i have the following $string: please enter your username: <input type=text size=50 name=username value=" "> When I display it on the browser, inside of a form, it displays the blank text field. Say the user enters a value in the text field, "John", and hits submit. I need the $string to be updated to the following: please enter your user name: <input type=text size=50 value="John"> I know it sounds wierd but I need the form to be inside of the string! Thanks in advance for any help! Link to comment https://forums.phpfreaks.com/topic/211901-form-field-inside-string/ Share on other sites More sharing options...
Vince889 Posted August 27, 2010 Share Posted August 27, 2010 Hi there! I am wondering if anyone knows how to handle strings that contain form fields, so when the form is submitted the fields inside the string are updated. For example say i have the following $string: please enter your username: <input type=text size=50 name=username value=" "> When I display it on the browser, inside of a form, it displays the blank text field. Say the user enters a value in the text field, "John", and hits submit. I need the $string to be updated to the following: please enter your user name: <input type=text size=50 value="John"> I know it sounds wierd but I need the form to be inside of the string! Thanks in advance for any help! I'm not understanding... you want the string to read this? $string = "please enter your user name: <input type=text size=50 value='John'>"; Link to comment https://forums.phpfreaks.com/topic/211901-form-field-inside-string/#findComment-1104459 Share on other sites More sharing options...
lfernando Posted August 27, 2010 Author Share Posted August 27, 2010 Yes, currently my $string (which is an entry in a database) reads this please enter your username: <input type=text size=50 name=username value=" "> I echo this $string as part of a form. Upon submitting the form, i want this $string to read this please enter your username: <input type=text size=50 name=username value="John"> Link to comment https://forums.phpfreaks.com/topic/211901-form-field-inside-string/#findComment-1104467 Share on other sites More sharing options...
fortnox007 Posted August 28, 2010 Share Posted August 28, 2010 Will this help you? $username = $_POST['username']; //get the value of the submitted html form $string = 'please enter your user name: <input type="text" size=50 value="'.$username.'">'; //put the value inside the string Hope it works for you. Il have changed the " with ' at the outside of the string btw, and added " " around text. If you have troubles with this let me know ill add some more code. Link to comment https://forums.phpfreaks.com/topic/211901-form-field-inside-string/#findComment-1104592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.