Hello,
I have a web form of type Name: (text field). I want to take the input entered in the text field and create a label with that input. Is this possible in Php? mind you I am new to this.
Eg: Name: activity.com
//create a label
activity.com
Thanks
Create a label dynamically
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Create a label dynamically
You can get the value from the form in from the $_POST superglobal array. Then probably easiest is to use HTML + CSS to format the output to print on a label. Look in to the media="print" property for CSS.
(#10850)
Re: Create a label dynamically
I dint look at media property of css thoroughly but I dont think I need that. What I am looking for is to take the input value using $_POST as you said and create <label name ="$_POST[$var]"></label>
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Create a label dynamically
The basic idea is:
However you should filter input coming in as escape it going out:
Even though it may not always be required it is best to consistently filter, validate and escape so nothing accidentally slips through.
Code: Select all
echo '<label name ="' . $_POST[$var] . '"></label>';Code: Select all
$label = preg_replace('/[^a-zA-Z0-9\_]/', '', $_POST[$var]);
echo '<label name ="' . htmlentities($label) . '"></label>';(#10850)