My Form Library

An example of one of my form library functions (I have a copious amount – for textarea, radio button, check box, select box – DB and array driven, hidden, etc. etc.):

/**
* Function to create a text box form element
*
* @param resource string $field
* @param resource string $size
* @param resource string $post_value
* @param resource string $text
* @return string
* @author Rebecca Anstett
* @see no url to provide
*/

function formTextBox($field, $size, $post_value, $text="", $js="")
{
$rt = "";
$field_name = $field["field_name"];
$field_title = $field["field_title"];
$required = $field["required"];

$rt .= "\t<tr>\n";
$rt .= "\t\t<td nowrap class=\"form-label\" valign=\"top\"><strong>{$field_title}</strong>:" . isRequired($required);
$rt .= "</td>\n";
$rt .= "\t\t<td class=\"form-field\" valign=\"top\">";
$rt .= <input type=\"text\" id=\"{$field_name}\" "name=\"{$field_name}\" value=\"{$post_value}\" size=\"{$size}\" {$js}/><br /><small>{$text}</small>";
$rt .= </td>\n";
$rt .= "\t</tr>\n";

return $rt;
} // END: function formTextBox

The above clearly outputs a text box control. The majority of the information for this element is defined in the application super array ($APP_CONFIG). $post_value is obtained from $_REQUEST. $text contains optional instructions. $js contains optional scripting functionality if required for the field. The call to isRequired() calls another function that determines if the field demands a value, as per $APP_CONFIG.

I realize that all of the escape quotes is on the ugly side – time permitting, I’ll probably clean up this functionality in the near future. Thus far, it’s elegant enough for the time being and I would prefer to build on my existing code-base, rather than cleaning up pesky legacy stuff that’s not technically broken.

Post a Comment

Your email is never shared. Required fields are marked *

*
*