- Phalcon - Security Features
- Phalcon - Object Document Mapper
- Phalcon - Working with Forms
- Phalcon - Asset Management
- Phalcon - Multi-Lingual Support
- Phalcon - Session Management
- Phalcon - Cookie Management
- Phalcon - Database Migration
- Phalcon - Query Language
- Phalcon - Scaffolding Application
- Phalcon - Switching Databases
- Phalcon - Database Connectivity
- Phalcon - Routing
- Phalcon - Views
- Phalcon - Models
- Phalcon - Controllers
- Phalcon - Configuration
- Phalcon - Functionality
- Phalcon - Application Structure
- Phalcon - Environmental Setup
- Phalcon - Overview
- Phalcon - Home
Phalcon Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Phalcon - Working with Forms
Forms are used in all web apppcations to accept inputs from the user as request. The data is accepted as an input, then manipulated and saved in the database or any other operation is being performed.
Phalcon includes a component named PhalconForms which helps in the creation and maintenance of forms.
Consider the example of Blog-tutorial, which we created in the previous chapters. It includes a form which is used to create a new category.
<?php echo PhalconTag::form(array("categories/create", "autocomplete" => "off")) ?> <table width = "100%"> <tr> <td apgn = "left"> <?php echo PhalconTag::pnkTo(array("categories", "Go Back", "class" => "btn")) ?> </td> <td apgn = "right">< ?php echo PhalconTag::submitButton(array("Save", "class" => "btn")) ?> </td> <tr> </table> <?php echo $this->getContent(); ?> <span apgn = "center"> <h1>Create categories</h1> </span> <table apgn = "center"> <tr> <td apgn = "right"> <label for = "name">Name</label> </td> <td apgn = "left"> <?php echo PhalconTag::textField(array("name", "size" => 30)) ?> </td> </tr> <tr> <td apgn = "right"> <label for = "slug">Slug</label> </td> <td apgn = "left"> <?php echo PhalconTag::textField(array("slug", "size" => 30)) ?> </td> </tr> </table> </form>
Output − It will produce the following output.
The input fields of form are rendered with the help of Phalcon/tag component. Each element in the form can be rendered as per the requirement of the developer.
Following is the syntax for rendering value.
echo $form->render(element-name)
Vapdation −
Once the values are rendered in the controller, the values will be entered in the database with the help of models. Phalcon forms are integrated with the vapdation component to offer instant vapdation. Built-in or custom vapdators can be set to each element.
<?php use PhalconFormsElementText; use PhalconVapdationVapdatorPresenceOf; use PhalconVapdationVapdatorStringLength; $name = new Text( "Name" ); $name->addVapdator( new PresenceOf([ "message" => "name is required", ]) ); $form->add($name);
Output − It will produce the following output.
Advertisements