user10099
user10099

Reputation: 1427

Joomla 2.5 - component development - using form

I am trying to add some form to my component, but I am not shure what naming conventions must be applied to work it correctly.

Currently I have a working form - it displays fields stored in XML file and loads data from database to it. However, when i try to submit this form (edit or add new records), it doesn't work. After pressing submit (save() method) it just redirects me and displays that record was edited successfuly but it wasn't. When I try to edit existing record, after pressing submit nothing happens and when I try to add new record, it just adds empty/blank record.

So I was doing a little debug and discovered, that problem is in the JController::checkEditId() method. It always returns false which means that JControllerForm::save() returns false as well and that's why it doesn't save it correctly. HTML code of form is correct and I can access the data by using global array $_POST.

I suspect that this problem is because of naming conventions in methods loadFormData, getForm of JModelAdmin class. I am not sure how to name that form.

So here is my code related to this problem:

Subcontroller for displaying the form - controllers/slideshowform.php

class SlideshowModelSlideshowForm extends JModelAdmin{

public function getForm($data = array(), $loadData = true){
    return $this->loadForm('com_slideshow.slideshowform', 'editform', array('load_data' => $loadData, 'control' => 'jform'));
}

protected function loadFormData(){  
        $data = JFactory::getApplication()->getUserState('com_slideshow.edit.slideshowform.data', array());
        if (empty($data)) 
        {
            $data = $this->getItem();
        }
        return $data;
}

public function getTable($table = "biometricslideshow"){
    return parent::getTable($table);
}

}

views/slideshowform/view.html.php

class SlideshowViewSlideshowForm extends JView{

public function display($tmpl = null){
        if (count($errors = $this->get('Errors'))) 
        {
            JError::raiseError(500, implode('<br />', $errors));
            return false;
        }
    $this->form = $this->get('form');
    $this->item = $this->get('item');
    JToolBarHelper::save('slideshowform.save');
    parent::display();
}

}

views/slideshowform/tmpl/default.php

<?php
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');

?>

<form method="post" action="<?php echo JRoute::_("index.php?option=com_slideshow&id=".(int) $this->item->id)?>" name="adminForm" id="slideshow-form">
  <fieldset class="adminform">
    <legend>Edit slide</legend>
    <table>
      <input type="hidden" name="task" value="">
      <?php echo JHtml::_('form.token'); ?>

      <?php

      foreach($this->form->getFieldset() as $field){
      ?>
      <tr><td><?php echo $field->label ?></td><td><?php echo $field->input ?></td></tr>

      <?php
      }
      ?>

    </table>
  </fieldset>
</form>

Can someone take o look, please?

Upvotes: 2

Views: 8269

Answers (1)

Alex
Alex

Reputation: 6470

you have to add controller SlideshowControllerSlideshowForm and code save method. In there you have to validate the form data and call SlideshowModelSlideshowForm->save event, then redirect with success/failure message.

Upvotes: 2

Related Questions