Jump to content

form field inside string?


lfernando

Recommended Posts

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

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'>";

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">

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.  8)

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.

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.