Custom field types

Custom field types, a forum discussion on Jojo CMS. Join us for more discussions on Custom field types on our Administration (backend and configuration) forum.

Back to Forum Index : Back to Administration (backend and configuration)   RSS
Harvey

Core Developer

Harvey

28 Mar 2008
Posts: 327

A user asks...

I am trying to create an admin page for adding/editing orders.

In the database, I have created 2 tables to hold the information, one for the general information about the order and the other to hold the items that is ordered.

How can I create a JOJO admin page that will show both tables on the one form.

Also I think that I will get the customer's name from an accounts table as well.


I thought this was a good question that should be moved to the forums so others can join the discussion.

Generally speaking, there is no built-in way of displaying this table relationship on a single screen - you can have the information editable from 2 separate screens easy enough, but combining onto one screen would require a custom field type.

Depending on your table structure, this probably isn't all that hard to do - assuming you don't need to edit the data, and you just need to display it.

We use custom fields all the time for adding extra functionality into admin forms. You would want to display the "order" screen, and "orderitems" would be a custom field type on the order screen, possibly on a separate tab to the other data.

We don't have much(any?) documentation on custom field types, but you can see an example of a custom field type in either of the maps plugins, the tags plugin, and probably others.

A custom field will need to be declared in api.php - see those plugins for example code. And then you will need to create a yourplugin/fields/FIELD-TYPE.php and an accompanying .tpl which control how your field behaves.
Probably, your custom field will want to query the database and display all the orderitems in a table, with totals at the bottom. If you don't need it to be editable (meaning you won't need to worry about the saving routines), this should be reasonably straightforward.

Otherwise, you may be able to get away with having the order data and the orderitem data on 2 separate screens. Personally, my shopping cart plugins send me an email with all the order/orderitem details in there, so I don't need to use the admin interface for getting order details (this is significantly easier to program, but it may not suit your purposes).

Custom field types are a pretty powerful piece of functionality, that most people wouldn't be aware of. I'll try to get some documentation online for these in coming weeks.
casey

28 Mar 2008
Posts: 7

For the customer name it is just for displaying.

However for the order items, I was wanting to be able to edit it.

Unfortunately, my client wants to be able to edit an order, so I can't just email the details to them.

I will see if I can get away with having 2 screens.
Harvey

Core Developer

Harvey

28 Mar 2008
Posts: 327

You can get custom field types to be able to edit the order items, but it will be more complicated.

The other approach is to write your own page / forms for editing / interacting with this data - similar to how we have done with the "edit redirects" screen.

The Jojo system does a pretty good job of auto-creating admin forms, but it doesn't handle everything.
casey

28 Mar 2008
Posts: 7

Thanks for that.

How much more complicated is it to get the custom field to add/edit the order items?

Is there any plugin that already does something like this?
Harvey

Core Developer

Harvey

28 Mar 2008
Posts: 327

It would be somewhat complicated, yes. What you are trying to do is similar in nature to the tags field type - which maintains tags stored in another database table. We faffed around developing that for a long time, but there were other factors contributing to this.

My suggestion in the above post may well be the best and quickest way to go - write your own admin interface for this particular functionality (which is how we had to do it in the old days). You can incorporate the page into the Jojo admin section easily, and make use of all the Jojo functions such as database query functions etc.

You will need to create the HTML for your form, do the error checking, and write a save / load routine for the data - which will be able to operate off both tables. And you can develop the user interface as much or as little as you like.
Back to Forum Index : Back to Administration (backend and configuration)   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.