পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

Phalcon - Working with Forms

Forms are used in all web applications 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 Phalcon\Forms 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 \Phalcon\Tag::form(array("categories/create", "autocomplete" => "off")) ?>  
   <table width = "100%"> 
      <tr> 
         <td align = "left">
            <?php echo \Phalcon\Tag::linkTo(array("categories", "Go Back", "class" => "btn")) ?>
         </td> 
         <td align = "right"><
            ?php echo \Phalcon\Tag::submitButton(array("Save", "class" => "btn")) ?>
         </td> 
      <tr> 
   </table>  
   
   <?php echo $this->getContent(); ?>  
   
   <div align = "center"> 
      <h1>Create categories</h1> 
   </div>  
   <table align = "center"> 
      <tr> 
         <td align = "right"> 
            <label for = "name">Name</label> 
         </td> 
         <td align = "left"> 
            <?php echo \Phalcon\Tag::textField(array("name", "size" => 30)) ?> 
         </td> 
      </tr> 
     
      <tr> 
         <td align = "right"> 
            <label for = "slug">Slug</label> 
         </td> 
         <td align = "left"> 
            <?php echo \Phalcon\Tag::textField(array("slug", "size" => 30)) ?> 
         </td> 
      </tr> 
   </table> 
</form>
Output − It will produce the following output.
Create Categories 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)
Validation
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 validation component to offer instant validation. Built-in or custom validators can be set to each element.
<?php  
use Phalcon\Forms\Element\Text; 
use Phalcon\Validation\Validator\PresenceOf; 
use Phalcon\Validation\Validator\StringLength;  

$name = new Text( 
   "Name" 
); 

$name->addValidator( 
   new PresenceOf([ "message" => "name is required", ]) 
); 

$form->add($name); 
Output − It will produce the following output.
Following Output

No comments:

Post a Comment