Not sure where to get started

herteljp@yahoo.com - March 30, 2009 - 17:08
Project:Form Panel
Version:6.x-1.0
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I read through the documentation and it talks about what the module can do. I cannot find anything on how to actually do it. Is there a getting started or tutorial that can help me get moving forward?

Thanks,

-Jeff

#1

VM - March 30, 2009 - 17:12

documentation link on the project page? = http://drupal.org/node/350241

#2

herteljp@yahoo.com - March 30, 2009 - 18:17

Been there. I must be missing something. I must be missing something in the process. Do I have to create some type of template file on the web server or is there suppose to be some type of layout screen for me to specify the fields?

Thanks,

-Jeff

#3

VM - March 30, 2009 - 18:26

It is important to note, however, that this module does nothing on its own. You must refer to one of the included themes from PHP code in order for there to be any effect.

the above quoted from the 1st page of documentation

#4

jamesmcd - April 4, 2009 - 21:47

I would have to agree that it is a bit confusing knowing where to start. It may well say:

It is important to note, however, that this module does nothing on its own. You must refer to one of the included themes from PHP code in order for there to be any effect.

However I am at a loss as to where the PHP code is placed.. is it in the teplate.php file?

If this is simple, then please excuse my ignorance and point me in the right direction..

Is there any other documentation.. screencasts etc that could shed better light on the process?

Many thanks

#5

Gribnif - April 9, 2009 - 15:02

Code is usually written directly in the .module or .inc files of your module, as it is an extension to Forms API. There's nothing, technically, to keep you from using it in a .tpl file, but Forms API code isn't normally used there.

There is no layout screen, because the purpose of the theme is to let you enter the row/column numbers of form elements directly in your PHP code. That would be difficult to do graphically, though Lullabot (I think?) has been working on a Javascript-based forms creator which could, in theory, be made to work with form_panel in the future.

I've been meaning to add some more concrete code examples, but haven't gotten around to it yet. In the meantime, here's a basic example I just whipped up. It is a modification to the code in modules/user/user.admin.inc:

<?php
function user_admin_access_form(&$form_state, $edit, $submit) {
 
$form = array('#theme' => 'form_panel_table');
 
$form['aid'] = array(
   
'#type' => 'value',
   
'#value' => $edit['aid'],
  );
 
$form['status'] = array(
   
'#type' => 'radios',
   
'#title' => t('Access type'),
   
'#default_value' => isset($edit['status']) ? $edit['status'] : 0,
   
'#options' => array('1' => t('Allow'), '0' => t('Deny')),
   
'#weight' => 2001,
  );
 
$type_options = array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host'));
 
$form['type'] = array(
   
'#type' => 'radios',
   
'#title' => t('Rule type'),
   
'#default_value' => (isset($type_options[$edit['type']]) ? $edit['type'] : 'user'),
   
'#options' => $type_options,
   
'#weight' => 2002,
  );
 
$form['mask'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Mask'),
   
'#size' => 30,
   
'#maxlength' => 64,
   
'#default_value' => $edit['mask'],
   
'#description' => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'),
   
'#required' => TRUE,
   
'#weight' => 3001,
  );
 
$form['submit'] = array('#type' => 'submit', '#value' => $submit, '#weight' => 9000);
 
$form['#submit'] = array('user_admin_access_form_submit');

  return
$form;
}
?>

If you compare this to the original source, you'll see that all I had to do was add three #weights and a #theme to get the radio buttons to appear side-by-side in a table--no separate theme function or inline HTML needed.

#6

aharown07 - April 16, 2009 - 22:24

I'm also wrestling with how to use the module. Are you saying core hacks are necessary? If a ...tpl.php option is possible, that sounds wiser, but creating templates for overrides is still a difficult concept for me so any hints on what to name the file, where to put it, etc. would be much appreciated.
Once I have that working, I can probably just plug values in here and there and see what happens until I understand what to do.

#7

Gribnif - April 17, 2009 - 14:01

@aharown07: I'm not saying you have to modify core. The example I gave is just that, an example of how a part of core *could* be modified to use form_panel.

Form_panel is aimed toward module and core developers, not people who are strictly theme developers. Code that uses form_panel is generally part of a .module file. It is added to functions like [modulename]_[nodetype]_form(), which use PHP code to generate forms. If you are using .tpl.php files to modify the appearance of forms, then form_panel is probably not going to help.

Assuming you are developing at the Forms API level, not the theme level, then perhaps it would help if you were to describe what form you would like to put into a table. If you post some source code, that would help even more.

#8

aharown07 - April 18, 2009 - 02:32

Ah. I get it now. Thanks.
Suggestion: someone might want to mention in a prominent place on the module home page "This module is for module developers" or something along those lines. I stumbled onto it in search of something I could install, enable, then manipulate standard Drupal forms or other people's module forms.

For others looking for that sort of thing, Form Defaults is the closest thing I've found, though it has limitations.

#9

Gribnif - April 20, 2009 - 15:56
Status:active» fixed

I have made the suggested change to the homepage.

I'm leaving this topic open until I do some more sample code.

#10

Gribnif - April 21, 2009 - 20:38
Status:fixed» active

Meant to not change the status. Changing it back.

#11

srwright - May 6, 2009 - 16:33

I tried submitting an issue but now it seems to be gone... anyways, has anyone been able to get this working with fieldsets? If so, can you please tell me how?

Thanks

P.S. Gribnif, any chance of seeing the code that generated the screenshot?

#12

Gribnif - May 6, 2009 - 19:25

@srwright: The other ticket is not missing, you're just not seeing it because I closed it. Closed tickets aren't shown, by default; you have to change the selections at the top of the Issues page. See #455272: Does not work in fieldsets.

The code to generate the form in the screenshot is part of a complex, custom module, and not something that would serve well as an example. I do plan to come up with some better examples, but have not yet had the time.

#13

Mike_Waters - August 16, 2009 - 04:21

anyways, has anyone been able to get this working with fieldsets? If so, can you please tell me how?

Rather than give the form the '#theme' => 'form_panel_table' attribute, give it to the fieldset, and give the items inside the fieldset a #weight.
Actually, they can be nested; you can give the $form the '#theme' => 'form_panel_table' attribute, as well as each fieldset, as long as you assign a #weight (or #form_panel_row/col) attribute to the fieldset(s). It will create a nested table structure, with the form encapsulated in a table, each fieldset encapsulated in tr/tds, and the items inside the fieldset encapsulated in another table.
ex, nesting:

<?php
    $form
= array('#theme' => 'form_panel_table');
   
$form['header'] = array(
       
'#type' => 'fieldset',
       
'#tree' => TRUE,
       
'#title' => t('this is a fieldset'),
       
'#theme' => 'form_panel_table',
       
'#weight' => 2001,
    );
   
$form['header']['name'] = array(
       
'#type' => 'textfield',
       
'#title' => t('Your name'),
       
'#description' => t('Please type your name here.'),
       
'#weight' => 2001,
    );
   
$form['header']['type'] = array(
       
'#type' => 'select',
       
'#weight' => 2002,
    );
   
$form['header']['submit'] = array(
       
'#type' => 'submit',
       
'#weight' => 2003,
    );
?>

This will create a structure like this:
<form method="post" action="/">
<table class="form-panel">
    <thead/>
    <tbody>
      <tr class="form-panel-row">
        <td class="form-panel-cell">
          <fieldset>
            <legend>this is a fieldset</legend>
              <table class="form-panel">
                <thead/>
                <tbody>
                  <tr class="form-panel-row">
                    <td class="form-panel-cell">
                      <label>Your name: </label>
                      <input type="text" />
                      <div class="description">Please type your name here.</div>
                    </td>
                    <td class="form-panel-cell">
                      <select ...... />
                    </td>
                    <td class="form-panel-cell">
                      <input type="submit ...... />
                    </td>
                  </tr>
                </tbody>
              </table>
            </fieldset>
          </td>
        </tr>
      </tbody>
  </table>
</form>

To not nest (i.e. the only tables are inside fieldsets), remove the #theme attribute from the $form and remove the #weight attribute from each fieldset.

Maintainer: Thanks for this great module! I can't tell you how many hours I have spent on form layout. Throw cross-browser compatibility into the mix, and it gets real hairy real fast.

 
 

Drupal is a registered trademark of Dries Buytaert.