If you’re anything like me, then you’ll want to see an example that shows how to use the purely static “Form” helper class. Below I coded a script that employs the helper to build an HTML form that collects data on a fictional user. Here it is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Using the static web form helper</title> </head> <body> <h1>Using the static web form helper</h1> <?php echo Form::open(array('action' => 'create', 'method' => 'post'));?> <p>First Name: <?php echo Form::input(array('type' => 'text', 'name' => 'fname'));?></p> <p>Last Name: <?php echo Form::input(array('type' => 'text', 'name' => 'lname'));?></p> <p>Email: <?php echo Form::input(array('type' => 'text', 'name' => 'email'));?></p> <p><?php echo Form::input(array('type' => 'submit', 'name' => 'send', 'value' => 'Create user'));?></p> <?php echo Form::close();?> </body> </html> As the above script shows, it’s extremely easy to build a basic web form by using the static methods provided by the “Form” helper class. Yet, the most important thing to note here is that any attempt to instantiate the class will result in a fatal error being triggered by the PHP engine, thanks to the declaration of its unimplemented private constructor. And with this final example, I’m finishing this last tutorial of the series. As always, feel free to introduce your own tweaks to all of the sample classes shown, so you can arm yourself with a better background in using restrictive constructors in PHP 5. Final thoughts Sad to say, we’ve come to the end of this series. Hopefully, the examples deployed in its tutorials have provided you with the right pointers to help you start using restrictive constructors within your own PHP 5 classes (when applicable, of course). As you learned in previous examples, even a detail as subtle as changing the level of accessibility of your constructors in certain cases may considerably improve the behavior of their originating classes. This is a concept that you should keep in mind when developing your own web applications. See you in the next PHP tutorial!
blog comments powered by Disqus |
|
|
|
|
|
|
|