PHP for Absolute Beginners by Thomas Blom Hansen & Jason Lengstorf
Author:Thomas Blom Hansen & Jason Lengstorf
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
Creating the Entry Input Form
Now that you have a dynamic navigation, you might as well use it for something meaningful. You could show an HTML form for the editor. Eventually, it should be possible to use the editor to create new blog entries. So, the editor form should have fields for creating an entry title and an entry article. There should also be a button for saving a new entry. While you’re at it, you might as well create a button for deleting an entry. Create a new file views/admin/editor-html.php, as follows:
<?php
//complete source code for views/admin/editor-html.php
return "
<form method='post' action='admin.php?page=editor' id='editor'>
<fieldset>
<legend>New Entry Submission</legend>
<label>Title</label>
<input type='text' name='title' maxlength='150' />
<label>Entry</label>
<textarea name='entry'></textarea>
<fieldset id='editor-buttons'>
<input type='submit' name='action' value='save' />
<input type='submit' name='action' value='delete' />
</fieldset>
</fieldset>
</form>
";
Most of the preceding code should be familiar ground, even if you see a few elements you might not have come across before. You can see two <fieldset> elements. They are used to group related form fields together. The main <fieldset> has a <legend> element. A <legend> is like a heading for a <fieldset> element.
The <input> element for the entry title has a maxlength attribute set to 150. You can probably guess that the displayed text field will only accept 150 characters. That’s perfect, because your entry table in the database accepts a maximum of 150 characters for new title attributes.
The maxlength attribute enhances form usability, in that it becomes harder for users to create an invalid title through the form. The maxlength attribute performs client-side validation and will only allow submission of valid titles. One thing to keep in mind is the fact that client-side validation is great for enhancing usability. It does not improve security, because you should expect a malicious user to be able to override client-side validation.
With a new editor view created, you have to update the controller so it shows the view. The controller for the editor can be found in controller/admin/editor.php. Change the code so it is like the following:
<?php
//complete source code for controllers/admin/editor.php
$editorOutput = include_once "views/admin/editor-html.php";
return $editorOutput;
These few lines of code should hook up the view and display it when the controller is loaded from admin.php. You can see it for yourself by reloading http://localhost/blog/admin.php?page=editor in your browser. You should expect to see the form.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Coding Theory | Localization |
Logic | Object-Oriented Design |
Performance Optimization | Quality Control |
Reengineering | Robohelp |
Software Development | Software Reuse |
Structured Design | Testing |
Tools | UML |
Deep Learning with Python by François Chollet(12577)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8301)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7697)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7091)
Microservices with Go by Alexander Shuiskov(6859)
Practical Design Patterns for Java Developers by Miroslav Wengner(6777)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6718)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6419)
Angular Projects - Third Edition by Aristeidis Bampakos(6129)
The Art of Crafting User Stories by The Art of Crafting User Stories(5652)
NetSuite for Consultants - Second Edition by Peter Ries(5586)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5392)
Kotlin in Action by Dmitry Jemerov(5066)
