|
|
|
This is another dynamic form element from my collection. I use this function in forms where a value of a database will be filled inside the form field. This is an easy way to get the right value inside the field if the form is submitted before and/or the process is stopped because some validation issue occurs. You can use the (optional) database value attribute as a default value, too.
| <?php
function create_form_field($formelement, $label, $db_value = "", $length = 25) {
$form_field = "<label for=\"".$formelement."\">".$label."</label>\n";
$form_field .= " <input name=\"".$formelement."\" type=\"text\" size=\"".$length."\" value=\"";
if (isset($_REQUEST[$formelement])) {
$form_field .= $_REQUEST[$formelement];
} elseif (isset($db_value) && !isset($_REQUEST[$formelement])) {
$form_field .= $db_value;
} else {
$form_field .= "";
}
$form_field .= "\"><br>\n";
return $form_field;
}
// example use
echo "<form method=\"post\">\n";
echo create_form_field("test", "test label", "db val");
echo "\n<input type=\"submit\" name=\"submit\">\n";
echo "</form>";
?> | | |
|
| Simple PHP Form Field Generator Categories : PHP, Beginner Guides, Form Processing, HTML and PHP | | | Check empty fields Categories : PHP, HTML and PHP, Form Processing | | | Sql Builder Categories : PHP, HTML and PHP, Databases, General SQL, Form Processing | | | PHP3: Formmail. Just a cgi formmail, but than in PHP. It is easy to use! Categories : HTML and PHP, Email, PHP, Perl, HTML and PHP | | | a function that builds an HTML select list from any mysql table. Categories : PHP, MySQL, HTML and PHP | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | Message of the Day - Random Message (Needs MySQL!) Categories : Databases, HTML and PHP, PHP, MySQL | | | Alternating background color for HTML table rows Categories : PHP, Databases, MySQL, HTML and PHP | | | Constantly refresh your PHP/HTML page data. Categories : PHP, HTML and PHP, Sybase | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | background music script for random notes in a frame Categories : PHP, Content Management, HTML and PHP | | | A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL | | | Random Image Display Categories : PHP, Filesystem, Graphics, HTML and PHP | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Automatically printing the contents of an sql table in MySQL. Categories : MySQL, PHP, HTML and PHP, Databases | |
| | | | Jose Santos wrote : 1283
This type of kinds is very easy and simple!
Why dont use templates ??
The templates has advantage to isolate the code (PHP) of the HTML.
Using templates, the code is more cleary and easy to understand.
See functions to work with templates insided in the PEAR of PHP.
Links:
http://pear.php.net/manual/en/
http://pear.php.net/package/HTML_Template_PHPLIB/docs/1.3/apidoc/HTML_Template_PHPLIB-1.3/Template_PHPLIB.html
| | | | Olaf Lederer wrote :1284
You are right it`s possible to do this with other technics. The example is meant for people which don`t want to use smarty (or whatever). I use this kind of function in some quick CMS forms and it works very fast for me.
| |
|
|
|