Page 1 of 1
Create a label dynamically
Posted: Tue Feb 12, 2008 10:29 am
by m_kk
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
Re: Create a label dynamically
Posted: Tue Feb 12, 2008 10:34 am
by Christopher
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.
Re: Create a label dynamically
Posted: Tue Feb 12, 2008 11:32 am
by m_kk
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>
Re: Create a label dynamically
Posted: Tue Feb 12, 2008 12:36 pm
by Christopher
The basic idea is:
Code: Select all
echo '<label name ="' . $_POST[$var] . '"></label>';
However you should filter input coming in as escape it going out:
Code: Select all
$label = preg_replace('/[^a-zA-Z0-9\_]/', '', $_POST[$var]);
echo '<label name ="' . htmlentities($label) . '"></label>';
Even though it may not always be required it is best to consistently filter, validate and escape so nothing accidentally slips through.