
Originally Posted by
TheRedDevil
I used a similar static class to allow me to type less a few years ago.
Though these days I really prefer readability over "lazy" coding. I will rather type 20 more characters and get a code I can scan in a second and know exactly what it does, than to use lots of classes to save me type a few characters.
I type fast enough anyway, so when looking on the large picture. I actually save time by typing everything, as what usally takes time is reading over code you created earlier to improve or bug fix.
I choose readability over shortcut any day. I do use a nice little form element generation class (Well, Its all procedural) that I can't live without now!!!
PHP Code:
//input type text
function input_text($id,$labelName,$labelClass='',$formClass='',$defaultValue='',$maxLength='255',$override=''){
$functionValue = ($defaultValue == '') ? '' : ' value="'.$defaultValue.'"';
$functionFormClass = ($formClass == '') ? '' : 'class="'.$formClass.'" ';
$functionLabelClass = ($labelClass == '') ? '' : ' class="'.$labelClass.'"';
echo '<label for="'.$id.'"'.$functionLabelClass.'>'.$labelName.'</label>';
echo '<input type="text" '.$functionFormClass.'name="'.$id.'" id="'.$id.'" maxlength="'.$maxLength.'"'.$functionValue.' '.$override.' /><br />';
}
//input type Password
function input_password($id,$labelName,$labelClass='',$formClass='',$maxLength='255',$override=''){
$functionFormClass = ($formClass == '') ? '' : 'class="'.$formClass.'" ';
$functionLabelClass = ($labelClass == '') ? '' : ' class="'.$labelClass.'"';
echo '<label for="'.$id.'"'.$functionLabelClass.'>'.$labelName.'</label>';
echo '<input type="password" '.$functionFormClass.'name="'.$id.'" id="'.$id.'" maxlength="'.$maxLength.'" '.$override.' /><br />';
}
//Text Area Input
function input_textarea($id,$labelName,$labelClass='',$formClass='',$defaultValue='',$override=''){
$functionCSSClass = ($cssClass == '') ? '' : ' class="'.$cssClass.'"';
echo '<label for="'.$id.'"'.$functionCSSClass.'>'.$labelName.'</label>
<textarea name="'.$id.'" id="'.$id.'"'.$override.'>'.$defaultValue.'</textarea>';
}
//Input type Checkbox
function input_checkbox($id, $labelName, $labelClass='', $formClass='',$checked='',$labelFirst='no',$override=''){
$functionFormClass = ($formClass == '') ? '' : 'class="'.$formClass.'" ';
$functionLabelClass = ($labelClass == '') ? '' : ' class="'.$labelClass.'"';
$functionChecked = ($checked == '') ? '' : ' checked="checked" ';
if($labelFirst == 'no'){
echo '<input type="checkbox" '.$functionFormClass.'id="'.$id.'" name="'.$id.'"'.$functionChecked.$override.'/>';
echo '<label'.$functionLabelClass.' for="'.$id.'">'.$labelName.'</label>';
}else{
echo '<label'.$functionLabelClass.' for="'.$id.'">'.$labelName.'</label>';
echo '<input type="checkbox" '.$functionFormClass.'id="'.$id.'" name="'.$id.'"'.$functionChecked.$override.'/>';
}
echo '<br />';
}
//Submit Button
function input_submit($id, $buttonLabel){
echo '<input class="button" type="submit" name="'.$id.'" value="'.$buttonLabel.'" />';
}
It saves me SOOOOOOOO much time and best of all it ensures consistency in how I "Write" my forms...
I have a few more portions that might not make sense to post here in my Forms Class that will create common Select boxes that include things like States, Number Ranges, etc... and that take an array as input and use the Key as the "Value" ofthe select while using the Value of the array as the Displayed choice.
Bookmarks