tags:

views:

217

answers:

5

I'm playing with some PHP for my website. How do I set the length of a text box that the user types in? Also, what is the code for making multiple line text boxes?

Thanks.

+1  A: 

The length of a textbox is done with CSS rules or with the size attribute of the tag.

ex. <input name="text" size="200" />

A multiple line text box is a <textarea></textarea> HTML tag.

Neither of these have anything to do with PHP, but rather are simple HTML.

jaywon
+7  A: 

I believe you really want to specify this in the HTML code as the maxlength attribute in the text box.

<input type="text" size="25" maxlength="25" value="Enter your name here!">

As for multilines, you want to set up a text area instead of a text box.

<textarea name="comments">
</textarea>

The size refers to the physical size of the box, where as the maxlength refers to the input data length.

Again, not PHP, but HTML.

Wayne Arthurton
Note that you should check the length of the input in PHP even though you define maxlength. Since there are ways around it.
Ólafur Waage
Very true, I shouldn't have assumed that people wouldn't validate their input.
Wayne Arthurton
A: 

In html use a <input type="text" size="25" maxlength="100"> for a single-line text field, and <textarea></textarea> for multiple-line text boxes. size="25" determines the number of characters that will be visible in the text field (in this case 25), and maxlength="100" determines the maximum number of characters that a user can input into that field (in this case 100).

davidg
+1  A: 

The preferred method of specifying a "size" (i.e. character width) of an input box is to use the width CSS property:

<!-- HTML -->
<input type="text" style="width: 42em;" />

/* CSS */
#search {
    width: 42em;
}

Multi-line text boxes are called text areas in HTML and the <textarea> element represents them, as the other answers state.

strager
+1 for being the only answer to mention using CSS for dimensions
Ben James
A: 

http://www.w3schools.com/TAGS/tag%5Ftextarea.asp

http://www.w3schools.com/TAGS/tag%5Finput.asp

So with the part of it, I need to line it up on the same line of html to other boxes. But it needs to line up along the top, any suggestions for that?

Not sure I understand, maybe you could show some code that illustrates the problem.

I recommend to install the Web developer add-on for firefox, that way you can edit css directly and see the results! https://addons.mozilla.org/en-US/firefox/addon/60

aland