2

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?

1 Answer 1

2

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.

3
  • I forget to mention that I already have that controller and it extends JControllerForm, which means it inherits save method. That method should do everything - it should call the model's method save() and then redirect, but instead of it, it just returns false.
    – user10099
    Apr 10, 2012 at 10:41
  • did you overload $view_list in your controller? Enabled debugging and check log. maybe checkEditId fails... Make sure you have access allowSave.
    – Alex
    Apr 10, 2012 at 13:43
  • No, I did not, there's no reason to. As I understood from code, $view_list variable only affects redirect location after successful save. Anyway, it seems to be working now. Probably something was messed up with sessions, because after apache restart and relog it works. Thanks
    – user10099
    Apr 10, 2012 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.