0

I have asked this on Stack Overflow but had no response at all. Hoping to gain some attention on here.

I know there are similar questions out there for this but none of them provide a working answer.

I am creating a form using $fieldset->addfield();. My code is the following:

$fieldset->addField('monday_open', 'select', array(
            'label'    => "Monday",
            'required' => false,
            'name'     => 'store_title',
            'values'   => array(
                '00' => '00',
                '01' => '01',
                '02' => '02',
                '03' => '03',
                '04' => '04',
                '05' => '05'
            ),
            'container_id' => 'some_row'
        ));
        $fieldset->addField('monday_close', 'select', array(
            'required' => false,
            'name'     => 'store_title',
            'values'   => array(
                '00' => '00',
                '01' => '01',
                '02' => '02',
                '03' => '03',
                '04' => '04',
                '05' => '05'
            ),
            'container_id' => 'some_row'
        ));

This, as you will know, prints 2 table columns per row, one label and one field. I am wanting multiple (3, 4, 5, etc) fields per row.

I am only new to Magento so it is very possible I am missing something.

Is there a way to customise the table that is used in these forms? I dont have a template linked in my layout xml. This file is as follows:

<layout version="0.1.0">
<stores_adminhtml_index_index>
    <reference name="content">
        <block type="stores/adminhtml_grid"  name="stores" />
    </reference>
</stores_adminhtml_index_index>

And here is the contents of Block/Adminhtml/Grid.php:

class Pivotal_Stores_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
{

    public function __construct() {
        $this->_controller = 'adminhtml_stores'; // Adminhtml/Stores
        $this->_blockGroup = 'stores';

        $this->getHeaderText = "Our Stores Management";

        $this->addButtonLabel = "Add a Store";
        parent::__construct();
    }
}

Really hoping there is a ~simple~ way to do this in php but, if not, can someone please let me know how I can create a custom layout/template for this?

  • Really?? 2 SE sites and not a single response? – Wildcard27 Oct 19 '15 at 0:47
  • Are you doing this because you want visually grouped fields? I don't think its possible with native magento admin forms. You would need custom template form & controller save action. – BENN1TH Oct 19 '15 at 3:14
  • Or put your desired grouped fields inside their own fieldset group. – BENN1TH Oct 19 '15 at 3:16
  • @BENN1TH thank you for your comment. I was starting to thing there was Magento dev strike! Can you point me in the right direction for learning how to create a custom template form and controller save action? I have build the whole module based on the Grid system. – Wildcard27 Oct 19 '15 at 4:36
  • See my answer.. – BENN1TH Oct 19 '15 at 8:52
1

How I added custom template & controller in admin edit form

In your adminhtml tab block Block/Adminhtml/MyExtension/Edit/Tab/MyExtension.php(See on GitHub)

//I added to this call a .phtml template file
$comments_block = $this->getLayout()
->createBlock('customermessages/adminhtml_edit_form_messages')
->setTemplate('path/to/my/phtml/file/template.phtml');
$this->setChild('form_after', $comments_block);

then my path/to/my/phtml/file/template.phtml (see on GitHub) - Its up to you to style to meet your grouped row requirments

<form action="<?php echo $this->getUrl('myextension/adminhtml_myextension/addReply') ?>" method="post" id="form-validate" enctype="multipart/form-data">


<!-- !!!!Needed to Authenticate -->
<?php echo $this->getBlockHtml('formkey')?>

<!-- My Field -->
<textarea type="text" name="message_content" id="message_content" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Message')) ?>" class="input-text " ></textarea>

<!-- My Submit Button -->
<button type="submit" title="<?php echo $this->__('Send Reply') ?>" class="button"><span><span><?php echo $this->__('Send Reply') ?></span></span></button>

and your controller action at /controllers/Adminhtml/MyExtensionController.php(See on GitHub)

public function addReplyAction()
{
  //do work, like save/edit collection

}

Hopefully theres enough info here to get you going but you will need to style your tabs layout to position your fields into one row, just copy the html layout from the native admin tab layout

good luck!

1

you can set template for the form. add your form fields in template file.

Spacename_Modulename_Block_Adminhtml_Modulename_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{ 
 public function __construct()
    {
        parent::__construct();
        $this->setTemplate('test/test.phtml');
        $this->setId('yourid');
         $this->setHtmlId('htmlid');
    } 
}

Reference

  • $this->setTemplate('test/test.phtml'); This is ignore by Magento coding standard tool. – Dhaduk Mitesh Sep 27 '18 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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