How to modify form and table templates?

Status
Not open for further replies.

belindab

New Member
Hi guys,
I've searched the forum and read the manual but just succeeded in getting confused, because there are two different formats of templates described and much of what I read doesn't apply to the current structure.

For the detail view I want to create something that looks like this:
http://eucalyptus-passion.com/species_form.html
where the fields in curly brackets will be replaced by the appropriate table elements (some of which will in fact be icons).

Can you please lead me on the path to enlightenment? I need to know where to insert the html and how to define the elements. If I can get this working then hopefully the table view will be easy to adapt :D

I have already created a new duplicate template to work on, and am ok with CSS, but pretty much a newbie with PHP (but I got some good books....)

Also, at the bottom of the detail view, I would like to have navigation, so that the visitor can move backwards or forwards between records. Sounds simple, but I can't find out where to turn it on.

When I get through this and know how to do a few things, I will be happy to help with the documentation :-\

Thanks for being here!
Belinda
 
Yup, the way the templates work got changed since the last ZIP was released.

Rob just finished the first cut at the latest 1.04 docs, and once we've proofread those, we'll be at the point where we can release a new ZIP and new docs.

I'm kind of snowed under right now, I'll try and get back to you later today about your specific questions.

-- hugh
 
Hi,
I know that Rob and Hugh are busy trying to get the next release ready. Can anyone could show me an example of a customised template where the field ids have been manually inserted, so that I can get the general idea? Both for tables and forms. Using 1.04.
Thanks a lot.
Belinda
 
Great, thanks Rob.. And hope there are no last minute gotchas on 1.04.

One small problem though - I can't see the 1.0.4 version of the Manual. The only one visible is rev 1.0.1

Regards,
Belinda
 
Re: How to modify form and table templates? Still need help!

I still can't see the new manual for 1.0.4. with the guide to modifying the templates ....

However I am making some (painfully slow) progress. But I am stuck with what to do with this foreach at the beginning of this part of the form template:

Code:
<?php
	foreach( $this->groups as $group ){?>
	<h3><?php echo $group->title;?></h3> 

	<table class="fb_group" id="group4" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td rowspan="3" width="120"><?php echo $elements['jos_fabrik_formdata_3___photo1']->element;?></td>
				<th width="240"><?php echo $elements['jos_fabrik_formdata_3___latin_name']->element;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___min_temp']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___max_height']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___growth']->label;?></th>
			</tr>
			<tr>
				<td><span class="common"><?php echo $elements['jos_fabrik_formdata_3___common_name']->element;?></span></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___min_temp']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___max_height']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___growth']->element;?></td>
			</tr>
			<tr>
			<td colspan="4"><?php echo $elements['jos_fabrik_formdata_3___description']->element;?></td>
			</tr>
	</table>
	<table class="fb_group feature" id="group11" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___foliage']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___flowers']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___bark1']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___aromatic']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___hedging']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___container']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___specimen']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___fire']->label;?></td>
			</tr>
			<tr>
				<td><?php echo $elements['jos_fabrik_formdata_3___foliage']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___flowers']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___bark1']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___aromatic']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___hedging']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___container']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___specimen']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___fire']->element;?></td>
			</tr>
	</table>
	<table class="fb_group feature" id="group4" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___chalk']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___salt']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___exposed']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___shade']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___boggy']->label;?></td>
			</tr>
			<tr>
				<td><?php echo $elements['jos_fabrik_formdata_3___chalk']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___salt']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___exposed']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___shade']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___boggy']->element;?></td>
			</tr>
		</table>
	
<?php
	}
	?>

Because my form is composed of three groups, it iterates through 3 times and prints out empty tables for the other two groups each time. If I don't use the foreach loop, It only displays data from the last group.

Can anyone help me to resolve this please?

Belinda
 
For some reason I can't get at the documents section at all, it tells me I need to login, even tho I'm logged in and am a Super Administrator. I've just spent a fruitless 20 minutes on the backend, trying to work out why this is happening. However, I do see the 1.04 manual listed in the DOCman component, so it should be there. I do have a copy locally, so if you want to PM me your email, I'll fire you off a copy.

I'm working on a solution for your template problem. I can see exactly what the problem is, but it's hard to just describe the answer, so I'm working on the exact PHP you'll need.

-- hugh
 
OK, instead of using a foreach loop, you'll need to reference each group by 'name' (the "Name" field from the Group admin page). Something like this:


Code:
	<?php $group = $this->groups->first_group_name; ?>
	<h3><?php echo $group->title;?></h3> 

	<table class="fb_group" id="group<?php echo $group->id;?>" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td rowspan="3" width="120"><?php echo $elements['jos_fabrik_formdata_3___photo1']->element;?></td>
				<th width="240"><?php echo $elements['jos_fabrik_formdata_3___latin_name']->element;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___min_temp']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___max_height']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___growth']->label;?></th>
			</tr>
			<tr>
				<td><span class="common"><?php echo $elements['jos_fabrik_formdata_3___common_name']->element;?></span></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___min_temp']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___max_height']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___growth']->element;?></td>
			</tr>
			<tr>
			<td colspan="4"><?php echo $elements['jos_fabrik_formdata_3___description']->element;?></td>
			</tr>
	</table>

	<?php $group = $this->groups->second_group_name; ?>
	<table class="fb_group feature" id="group<?php echo $group->id;?>" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___foliage']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___flowers']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___bark1']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___aromatic']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___hedging']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___container']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___specimen']->label;?></td>
				<td width="60"><?php echo $elements['jos_fabrik_formdata_3___fire']->label;?></td>
			</tr>
			<tr>
				<td><?php echo $elements['jos_fabrik_formdata_3___foliage']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___flowers']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___bark1']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___aromatic']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___hedging']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___container']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___specimen']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___fire']->element;?></td>
			</tr>
	</table>

	<?php $group = $this->groups->third_group_name; ?>
	<table class="fb_group feature" id="group<?php echo $group->id;?>" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___chalk']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___salt']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___exposed']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___shade']->label;?></td>
				<td width="80"><?php echo $elements['jos_fabrik_formdata_3___boggy']->label;?></td>
			</tr>
			<tr>
				<td><?php echo $elements['jos_fabrik_formdata_3___chalk']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___salt']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___exposed']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___shade']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___boggy']->element;?></td>
			</tr>
		</table>

Also note I've changed the 'id' for each table, so it correctly sets it to the correct group ID. Not a huge deal, but worth getting right.

So all you should need to change above are the three ...

<?php $group = $this->groups->third_group_name; ?>

... lines, and change the 'third_group_name' bit to match your group names.

Hopefully this should do what you need.

-- hugh
 
Hi Hugh,
Sorry, must have got brain fag here.

<?php $group = $this->groups->first_group_name; ?>

You say I have to replace 'first_group_name' with the actual name of the group, in this case it is 'Eucalyptus', which is group4. I don't figure how this can be used in the above construction. Could you show me please?

Cos at the moment I am getting nothing at all displayed whatever I try.

Sorry this OO stuff is not something I am familiar with.
Thanks,
Belinda
 
Ooops, my bad. Those lines should read:

<?php $group = $this->groups[group_name]; ?>

I sometimes get confused between what how my debugger console wants me to refer to objects as, and what PHP wants. So use the [group_name] form, not the ->group_name one.

The 'name' is whatever name you have given the groups in your Group admin. If you edit the group in the Fabrik backend, you should see that it has a "Name" and a "Title". The Title is printed on the form as the group title, and can include things like spaces and other non-alphanumeric characters. The 'Name' is used internally by Fabrik, and should be strictly alphanumeric or _, no spaces.

So you might have Title set to "Eucalyptus", and the "Name" to eucalyptus_group. In which case, change the appropriate line in that template to ...

<?php $group = $this->groups[eucalyptus_group]; ?>

And so on for the other two groups.

-- hugh
 
Yeahhhh! You're a star, Hugh. ;D Now I'm really cooking with gas. Thanks a million.

I'll see how I get on with the documentation for table templates and let you know about that.

Now, re: the other part of the question

Also, at the bottom of the detail view, I would like to have navigation, so that the visitor can move backwards or forwards between records.

This would keep the look and feel consistent with other parts of Joomla. Does this behaviour exist within Fabrik? Can I cut and paste it from somewhere?

Cheers,
Belinda
 
That would be great if you can get it to work for 1.0.5.

How do I access unfuddle? I tried with user fabrik_anonymous and password anonymous but it didn't like it......

Well done for getting 1.0.4 out.

Belinda
 
Regarding anonymous login to Unfuddle. The username is actually 'anonymous', it's only when using SVN we have to pre-pend usernames with the Unfuddle project name, hence fabrik_anonymous.

I'm still working (in my "copious spare time') on the Unfuddle API, so we can provide ticket feedback and status on this site. But we are very probably going to open up the 'anonymous' account a little so you can at least log in directly to Unfuddle and view ticket status.

Watch this ---> <--- space.

-- hugh
 
I'm pretty sure that figuring out this code is key to what I want to do, but I can't get it to work for the life of me. How would this code:

Code:
<?php $group = $this->groups[first_group_name]; ?> **Doesn't first_group_name need to be in quotes?**
	<h3><?php echo $group->title;?></h3> 

	<table class="fb_group" id="group<?php echo $group->id;?>" width="480">
		<?php $elements = $group->elements
			?>
			<tr>
				<td rowspan="3" width="120"><?php echo $elements['jos_fabrik_formdata_3___photo1']->element;?></td>
				<th width="240"><?php echo $elements['jos_fabrik_formdata_3___latin_name']->element;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___min_temp']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___max_height']->label;?></th>
				<th width="40"><?php echo $elements['jos_fabrik_formdata_3___growth']->label;?></th>
			</tr>
			<tr>
				<td><span class="common"><?php echo $elements['jos_fabrik_formdata_3___common_name']->element;?></span></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___min_temp']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___max_height']->element;?></td>
				<td><?php echo $elements['jos_fabrik_formdata_3___growth']->element;?></td>
			</tr>
			<tr>
			<td colspan="4"><?php echo $elements['jos_fabrik_formdata_3___description']->element;?></td>
			</tr>
	</table>

or just the relevant parts of that code, need to be rewritten if I have the following setup:
I only have one group, one form and one table. My group is called Demographics and the id (the number to the left of the name on the admin page?) is 2. The form is called Clients, and its id is 1.

I've been screwing around with this code for awhile, and nothing ever shows up! All I get is an unfilled table. Can someone help me out?
 
do you have a page we can look at?
You can get the exact data structure by adding this to the top of your tempalte:

Code:
<pre><?php print_r($this->groups);?></pre>

first_group_name should be inquotes and should be replaced i think with "Demographics"

Rob
 
Maybe it's a PHP version thing, but my PHP doesn't seem to care if associative array subscripts are in qoutes or not. But of course it wouldn't hurt to put them in there either way.

-- hugh
 
Here's the page I'm currently fooling around with:

http://www.uab.edu/uabsap/courtdb2/index.php?option=com_fabrik&Itemid=38

It doesn't do much of anything right now, because I'm just trying to make a custom template that displays an entry in the table, so there's not any code to organize the page. For example, all I have in my custom template right now is this:

Code:
<?php $group = $this->groups['Demographics']; ?> 
<?php $elements = $group->elements; ?>
<?php echo $elements['jos_fabrik_formdata_0___social']->element;?>

I tried making a template.php with just
Code:
<pre><?php print_r($this->groups);?></pre>

And nothing appeared when I viewed the table. However, I changed it to
Code:
<?php print_r($this->_data);?>

And all of this stuff popped up:
Code:
Array ( [0] => Array ( [0] => stdClass Object ( [clients.placement] => ASAP 
[clients.first_name] => NAthan [clients.middle_name] => O 
[clients.last_name] => C [clients.gender] => Male [clients.DOB] => 01/01/01 
[clients.social] => 111111111 [clients.address1] => 1028 50th street 
[clients.address2] => [clients.city] => Nowhere [clients.state] => NY 
[clients.country] => United States of America [clients.zipcode] => 35211 
[clients.phone1] => 555-555-5555 [clients.phone2] => 
[clients.guardian] => Mother & Father [clients.insurance] => Blue Cross Blue Shield [clients.charges] => Righteousness [clients.custody] => Jail 
[clients.gainq] => 1 million [clients.id] => 6 [__pk_val] => 6 
[_cursor] => 0 [_total] => 2 ) [1] => stdClass Object ( [clients.placement] => Pending [clients.first_name] => Blah [clients.middle_name] => Blah 
[clients.last_name] => Blah [clients.gender] => Male [clients.DOB] => 
[clients.social] => 0 [clients.address1] => [clients.address2] => 
[clients.city] => [clients.state] => AL [clients.country] => United States of America [clients.zipcode] => 0 [clients.phone1] => [clients.phone2] => 
[clients.guardian] => Mother & Father [clients.insurance] => Blue Cross Blue Shield [clients.charges] => [clients.custody] => [clients.gainq] => 
[clients.id] => 7 [__pk_val] => 7 [_cursor] => 1 [_total] => 2 ) ) )

Which just shows the two temporary entries in the table in the database.
 
Well, I've learned a few things. The code on this thread is for forms and only works as a form templates; if you try to use it for a table template nothing pops up, of course.

I've got this, though:
(in Table Template)
Code:
print_r($this->_data) 
Array
(
  [0] => Array
    (
      [0] => stdClass Object
        (
          [clients.placement] => ASAP
          [clients.first_name] => NAthan
          [clients.middle_name] => O
          [clients.last_name] => Cook
          [clients.gender] => Male
          [clients.DOB] => 01/11/11
          [clients.social] => 111111111
          [clients.address1] => 1111 50th street
          [clients.address2] => 
          [clients.city] => Arab
          [clients.state] => AL
          [clients.country] => United States of America
          [clients.zipcode] => 35211
          [clients.phone1] => 205-595-5555
          [clients.phone2] => 
          [clients.guardian] => Mother & Father
          [clients.insurance] => Blue Cross Blue Shield
          [clients.charges] => Righteousness
          [clients.custody] => On the Lamb
          [clients.gainq] => 1 million
          [clients.id] => 6
          [__pk_val] => 6
          [_cursor] => 0
          [_total] => 2
        )

So I guess the way to get at a value directly would be something like this:
Code:
<?php echo $this->_data[0][0]->clients.id; ?>
but this doesn't work!

or maybe this?

Code:
<?php echo $this->data[0]['clients.id'] ?>

I'm a newb at php, if you can't already tell.

I'm using fabrik 1.04 btw.

Edit:
Ok, I've at least figured this out. Rather than using $this->_data to get the elements, you should use $this->rows. $this->rows has all the elements changed to the 'database___elementname' format, so you can access them. Here's code to illustrate this...


<pre>print_r($this->rows);</pre> outputs this for me:
Code:
Array
(
  [0] => Array
    (
      [0] => stdClass Object
        (
          [clients.placement] => ASAP
          [clients___placement] => ASAP
          [clients.first_name] => NAthan
          [clients___first_name] => NAthan
          [clients.middle_name] => O
          [clients___middle_name] => O
          [clients.last_name] => Cook
          [clients___last_name] => Cook
          [clients.gender] => Male
          [clients___gender] => Male
          [clients.DOB] => 01/11/11
          [clients___DOB] => 01/11/11
          [clients.social] => 111111111
          [clients___social] => 111111111
          [clients.address1] => 1111 50th street
          [clients___address1] => 1111 50th street
          [clients.address2] => 
          [clients___address2] => 
          [clients.city] => Arab
          [clients___city] => Arab
          [clients.state] => AL
          [clients___state] => AL
          [clients.country] => United States of America
          [clients___country] => United States of America
          [clients.zipcode] => 35211
          [clients___zipcode] => 35211
          [clients.phone1] => 205-595-5555
          [clients___phone1] => 205-595-5555
          [clients.phone2] => 
          [clients___phone2] => 
          [clients.guardian] => Mother & Father
          [clients___guardian] => Mother & Father
          [clients.insurance] => Blue Cross Blue Shield
          [clients___insurance] => Blue Cross Blue Shield
          [clients.charges] => Righteousness
          [clients___charges] => Righteousness
          [clients.custody] => On the Lamb
          [clients___custody] => On the Lamb
          [clients.gainq] => 1 million
          [clients___gainq] => 1 million
          [clients.id] => 6
          [clients___id] => 6
          [__pk_val] => 6
          [_cursor] => 0
          [_total] => 2
          [fabrik_delete] => 
          [fabrik_edit] => Edit
          [fabrik_view] => View
        )

      [1] => stdClass Object
        (
          [clients.placement] => Pending
          [clients___placement] => Pending
          [clients.first_name] => Blah
          [clients___first_name] => Blah
          [clients.middle_name] => Blah
          [clients___middle_name] => Blah
          [clients.last_name] => Blah
          [clients___last_name] => Blah
          [clients.gender] => Male
          [clients___gender] => Male
          [clients.DOB] => 
          [clients___DOB] => 
          [clients.social] => 0
          [clients___social] => 0
          [clients.address1] => 
          [clients___address1] => 
          [clients.address2] => 
          [clients___address2] => 
          [clients.city] => 
          [clients___city] => 
          [clients.state] => AL
          [clients___state] => AL
          [clients.country] => United States of America
          [clients___country] => United States of America
          [clients.zipcode] => 0
          [clients___zipcode] => 0
          [clients.phone1] => 
          [clients___phone1] => 
          [clients.phone2] => 
          [clients___phone2] => 
          [clients.guardian] => Mother & Father
          [clients___guardian] => Mother & Father
          [clients.insurance] => Blue Cross Blue Shield
          [clients___insurance] => Blue Cross Blue Shield
          [clients.charges] => 
          [clients___charges] => 
          [clients.custody] => 
          [clients___custody] => 
          [clients.gainq] => 
          [clients___gainq] => 
          [clients.id] => 7
          [clients___id] => 7
          [__pk_val] => 7
          [_cursor] => 1
          [_total] => 2
          [fabrik_delete] => 
          [fabrik_edit] => Edit
          [fabrik_view] => View
        )

    )

)

So the code I put in my custom table Template to print a value from the table is this:

Code:
<?php echo $this->rows[0][0]->clients___social; ?>

I still have more questions but I think I can figure most of them out on my own.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top