User Rating: 1 / 5

Star ActiveStar InactiveStar InactiveStar InactiveStar Inactive
 

In Joomla from 2.5 to be done in Class JForm to add to the convenience. Flexibility to create a form And running through the field with field preparation of standard form. I run several at Standard form field types by building takes the form of XML.

creating forms in the models folder and create a file. hello.xml model is built in as root and use the tag form to consist in the field to take the field before the main attribute like name Class Label Type Required.

com_helloworld/models/forms/hello.xml

<?xml version="1.0" encoding="utf-8"?>
<form>
        <fieldset name="hello_form">
                <field 
                        name="name" 
                        type="text"
                        class="inputbox"
                        label="Name"
                        required="true"
                />

                <field 
                        name="detail" 
                        type="textarea"
                        class="inputbox"
                        label="Detail"
                        required="true"
                        rows="5"
                />
        </fieldset>
</form>

 

- Create hello.php file in the models folder, open and code.

com_helloworld/models/hello.php

 

<?php
defined('_JEXEC') or die('Restricted access');

class HelloworldModelHello extends JModelForm 
{
       
        function getForm($data = array(), $loadData = true) 
        {
               
                $options = array('control' => 'jform', 'load_data' => $loadData);

               
                $form = $this->loadForm('com_helloworld.hello', 'hello', $options);
               
                if (empty($form)) {
                        return false;  
                }
                
                return $form;
        }

}
?>

 

Modify files in the folder view.html.php views/hello.

com_helloworld/views/hello/view.html.php

 

<?php
defined('_JEXEC') or die('Restricted access');

class HelloworldViewHello extends JViewLegacy 
{

        function display($tpl = null)
        {
                
                $this->form = $this->get('Form');
                $this->addToolbar();
                
                parent::display($tpl);
        }
        
        
       
        function addToolbar()
        {
                JToolbarHelper::save(); 
                JToolbarHelper::cancel();
        }
    
}

 

-Edit the default.php file in the tmpl.

com_helloworld/views/hello/tmpl/default.php

<?php 
defined('_JEXEC') or die('Restricted access');


JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');

?>
<script>
    Joomla.submitbutton = function(task) {
        if (task == 'cancel' || document.formvalidator.isValid(document.id('adminForm'))) {
            Joomla.submitform(task, document.getElementById('adminForm'));
        } else {
            alert('Form Invaild');
        }
    }
</script>

<form action="<?php echo JRoute::_('index.php?option=com_helloworld&c=hello'); ?>" name="adminForm" id="adminForm" method="post" class "form-validate form-horizontal">
  
    <fieldset>
        
        <?php foreach ($this->form->getFieldset('hello_form') as $field) { ?>
            <div class="control-group">
                <div class="control-label">
                    <?php echo $field->label; ?>
                </div>
                <div class="controls">
                    <?php echo $field->input; ?>
                </div>
            </div>
        <?php } ?>
        
        <input type="hidden" name="task" />
        <?php echo JHtml::_('form.token'); ?>
        
    </fieldset>
    
</form>
?>

 

Summary File:

com_helloworld/helloworld.php

com_helloworld/controllers/hello.php

com_helloworld/models/hello.php

com_helloworld/models/forms/hello.xml

com_helloworld/views/hello/view.html.php

com_helloworld/views/hello/tmpl/default.php

 

Display:

 

 

 

Chapter 10 - Saving data into database Component Development

Recent Topics
Subject
Post Reply
Open
Recent
Plugin MDGallery
By MattijsFranken Sun 25 Oct 2020 11:35 pm Board English Language
1
58
Mon 26 Oct 2020 6:31 am By mindphp
Does MD Watermark work under Joomla 3.9.20?
By Balazs Thu 16 Jul 2020 4:48 pm Board English Language
6
905
Thu 16 Jul 2020 10:31 pm By Balazs
The program calculates the PMT
By prmindphp Wed 20 May 2020 6:45 pm Board English Language
1
271
Thu 21 May 2020 5:57 pm By prmindphp
Helper for calculating NPER values
By prmindphp Tue 19 May 2020 6:55 pm Board English Language
1
253
Thu 21 May 2020 5:59 pm By prmindphp
Program that will be used for home loan calculations
By prmindphp Mon 18 May 2020 6:49 pm Board English Language
1
275
Thu 21 May 2020 6:02 pm By prmindphp
Tools that will help calculate car tax
By prmindphp Thu 14 May 2020 7:00 pm Board English Language
1
275
Fri 15 May 2020 12:03 am By prmindphp
Helper to create slidershow, Module Product Slide of MooZiiCart
By prmindphp Thu 30 Apr 2020 6:32 pm Board English Language
0
339
Thu 30 Apr 2020 6:32 pm By prmindphp
Helper in searching products by category and keywords with Module Ajax Search of MooZiiCart
By prmindphp Tue 28 Apr 2020 6:17 pm Board English Language
0
330
Tue 28 Apr 2020 6:17 pm By prmindphp
Helper to restore the system to clear data, Plugin System MRestore
By prmindphp Fri 24 Apr 2020 7:05 pm Board English Language
0
313
Fri 24 Apr 2020 7:05 pm By prmindphp
Creating social share buttons, share the website's content to Social Media With Plugin Content Msocial
By prmindphp Wed 22 Apr 2020 7:05 pm Board English Language
0
278
Wed 22 Apr 2020 7:05 pm By prmindphp
Create Content Marketing and Product with Content Product Match of MooZiiCart
By prmindphp Tue 21 Apr 2020 7:19 pm Board English Language
0
331
Tue 21 Apr 2020 7:19 pm By prmindphp
Filtering for find the product with Module Filter product of MooZiiCart
By prmindphp Thu 09 Apr 2020 6:51 pm Board English Language
0
330
Thu 09 Apr 2020 6:51 pm By prmindphp
Template Megadeal of MooZiiCart for creating websites to sell products online
By prmindphp Fri 03 Apr 2020 6:45 pm Board English Language
0
469
Fri 03 Apr 2020 6:45 pm By prmindphp
[MooZiiCart] [Module] Displaying products that customers are interested by Wishlist Module
By prmindphp Fri 27 Mar 2020 5:46 pm Board English Language
0
741
Fri 27 Mar 2020 5:46 pm By prmindphp
Show the Bestsellers Product by Module Bestseller
By prmindphp Wed 25 Mar 2020 6:04 pm Board English Language
0
465
Wed 25 Mar 2020 6:04 pm By prmindphp
Show Products Category by Module Category
By prmindphp Tue 24 Mar 2020 6:07 pm Board English Language
0
588
Tue 24 Mar 2020 6:07 pm By prmindphp
Plugin System MZC Auto Close to enable the open and close odering system
By prmindphp Wed 19 Feb 2020 6:38 pm Board English Language
0
3169
Wed 19 Feb 2020 6:38 pm By prmindphp
MDPartner Component for store client data in CRM system
By prmindphp Sat 25 Jan 2020 3:04 pm Board English Language
0
928
Sat 25 Jan 2020 3:04 pm By prmindphp
i am looking for help
By Anonymous Tue 14 Jan 2020 5:46 pm Board English Language
1
961
Tue 14 Jan 2020 6:03 pm By noppadonsk
Dot Net Training
By Poonaam Fri 10 Jan 2020 2:20 pm Board English Language
0
1209
Fri 10 Jan 2020 2:20 pm By Poonaam