CREATING A TEXT FIELD

    print $query->textfield(-name=>'field_name',
			    -default=>'starting value',
			    -size=>50,
			    -maxlength=>80);
	-or-

    print $query->textfield('field_name','starting value',50,80);

textfield will return a text input field.

Parameters
  • The first parameter is the required name for the field (-name).

  • The optional second parameter is the default starting value for the field contents (-default).

  • The optional third parameter is the size of the field in characters (-size).

  • The optional fourth parameter is the maximum number of characters the field will accept (-maxlength).

  • As with all these methods, the field will be initialized with its previous contents from earlier invocations of the script. When the form is processed, the value of the text field can be retrieved with:

           $value = $query->param('foo');
    

    If you want to reset it from its initial value after the script has been called once, you can do so like this:

           $query->param('foo',"I'm taking over this value!");
    

    NEW AS OF VERSION 2.15: If you don't want the field to take on its previous value, you can force its current value by using the -override (alias -force) parameter:

        print $query->textfield(-name=>'field_name',
    			    -default=>'starting value',
    			    -override=>1,
    			    -size=>50,
    			    -maxlength=>80);
    

    JAVASCRIPTING: You can also provide -onChange, -onFocus, -onBlur and -onSelect parameters to register JavaScript event handlers. The onChange handler will be called whenever the user changes the contents of the text field. You can do text validation if you like. onFocus and onBlur are called respectively when the insertion point moves into and out of the text field. onSelect is called when the user changes the portion of the text that is selected.