As I explained in the segment that you just read, it’s mandatory to give the HTML form helper class the ability to construct basic text areas, to expand its existing functionality a bit further. Therefore, in the following lines I included the definition of a brand method that will be added to the helper later on, which renders those HTML elements in a straightforward fashion. Take a look at it, please: // render <textarea> tag public static function textarea(array $attributes) { $html = '<textarea'; $content = ''; if (!empty($attributes)) { foreach ($attributes as $attribute => $value) { if (in_array($attribute, array('rows', 'cols', 'id', 'class', 'name', 'value')) and !empty($value)) { if ($attribute === 'value') { $content = $value; continue; } $html .= ' ' . $attribute . '="' . $value . '"'; } } } return $html . '>' . $content . '</textarea>'; } From the previous code fragment, it’s easy to see how the “textarea()” static method functions. As its name suggests, all it does is generate the HTML markup required to render text area elements. Additionally, the method performs a basic checking process to determine which HTML attributes are valid to assign to the text area being created. This process, logically, is subject to further improvements as well. So far, so good, right? Having defined and implemented a method that constructs text areas in web forms, the helper class is almost set. Of course, it’s possible to add more methods to it that render selects, buttons, <fieldset> and <legend> elements, but this task will be left as homework for you, for those moments where you’re bored and want to do something really useful. All right, now that you grasped the logic behind the previous “textarea()” methods, it’s time to show the complete source code of the from helper class, after including this last rendering method. This topic will be covered in the section to come. Thus, jump ahead and read the following lines.
blog comments powered by Disqus |
|
|
|
|
|
|
|