Create a label dynamically

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m_kk
Forum Newbie
Posts: 8
Joined: Tue Feb 12, 2008 10:26 am

Create a label dynamically

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Create a label dynamically

Post 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.
(#10850)
m_kk
Forum Newbie
Posts: 8
Joined: Tue Feb 12, 2008 10:26 am

Re: Create a label dynamically

Post 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>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Create a label dynamically

Post 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.
(#10850)
Post Reply