_
_ Handy PHP
_
_
Tutorials, Scripts, Information And Other Resources arrow PHP Functions arrow Build Input Field
Friday, 21 November 2008
_

Refer A Friend using Revolution Money Exchange
Resource Menu
Handy PHP Store
Free Domain Name
PHP Functions
PHP Downloads
PHP Newsfeeds
PHP Tutorials
Webmaster Tools
User Login
TalkPHP
Get friendly help with your PHP problems for free.
www.talkphp.com
The PHP Resource Index
Handy PHP
Free PHP Help!


 
This Section Is Scheduled
For Maintenance

    The format of the PHP Functions section here at Handy PHP needs some attention soon.  Recent changes to the website have brought to light some significant layout problems with this section.  The need for a standard format for all functions has resulted in the problems.  Each function will be reformated, enhanced, archived, and updated as time allows. In the meantime, some screen resolutions may display a distorted version of the website.
Thank you for your visit and patience.

If you encounter any major problems with viewing the functions, please inform us via the forums.
If you are unable to find what you needed here, please let us know what you wanted in the forums so that we may add relevant content in the future.

Build Input Field Print E-mail
User Rating: / 1
PoorBest 
PHP Resources - Handy PHP Functions
Written by M. L. Griswold   
Saturday, 16 September 2006
Description:
 
string build_input_field(string type, string name[, string value[, int size[, int maxlength[, string option[, string prepend[, string append]]]]]])
     
 
This handy PHP function will reduce the amount of typing you do when you are designing HTML forms.  While all you need to enter is the input type and name for the function to work, it offers the flexability to build very complex input tags if needed.  The "option" parameter allows for extra arguments to be inserted inside of the input tag while the "prepend" and "append" parameters allow for additional output to be added before and after the tag.
     
Function:
 
function build_input_field($type, $name, $value = '', $size = '', $maxlength = '', $option = '', $prepend = '', $append = '') {
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!
    $field = "<input type=\"$type\" name=\"$name\"";
    if($value) $field .=  " value=\"$value\"";
    if($size) $field .=  " size=\"$size\"";
    if($maxlength) $field .=  " maxlength=\"$maxlength\"";
    if($option) $field .=  " $option";
    $field .= ">";
    $field = $prepend.$field.$append;
    return $field;
}
     
Usage:
 
echo build_input_field('text', 'sample', 'Sample Text', 20, '', 'title="Insert Some Text Here!"', "\tTest Field: ", "<br>\n");
     
Result:
 
	Test Field: <input type="text" name="sample" value="Sample Text" size="20" title="Insert Some Text Here!"><br>
				
     
Notes:
 
This is only really practical if you are planning to add a lot of input fields manually.  Using a loop to build a form would be a good substitute for this kind of manual form creation.  This will of course work for text, hidden, password, button, reset, and submit input fields.


Discuss this article on the forums. (1 posts)
 
< Prev   Next >

_
 
_
_
© 2008 Handy PHP