FORUMS CLOSED DUE TO SPAM. YOU STILL CAN ADD POST!

page part forms (custom fields)

Feed 87 posts, 17 voices

Avatar
70 posts

Hello all,

today I want to contribute my second plug-in to the frog community. It’s called page_part_forms and allows the page admin to create a custom form based on the page_parts for page editing.

The source as well as a description is available at github. A zip file for each official version can be found in the download section.

From the README:

Frog has a simple but powerful mechanism to handle content. The content is organised in pages and each page consists of at least one page part (called “body”). New page parts can easily added and accessed for content presentation, but only one page part can be active at a time. A page part is a basic text field that can hold any kind of content (e.g. PHP script, HTML, etc.). Page part forms fills the gap between the generic structure and a custom interface. With this plug-in a form can be defined that is shown instead of the frog build in tab view. The form does not only contain basic text field, but allows e.g. selections and date fields.

The wiki contains simple instructions and will be extended over time by user feedback.

Please give it a try and write your feedback to this thread.

PS: please note the dependencies against the jQuery plug-in and the page_metadata plug-in, as well as the little changes to the frog core (replace “include” with “include_once”).

Code changes
frog/app/controllers/PluginController.php, line 75:

replace “include $plugin->file;” with “include_once $plugin->file;”

frog/app/views/page/edit.php, line 211

replace: <?php Observer::notify('view_page_edit_popup'); ?>
with: <?php Observer::notify('view_page_edit_popup', $page); ?> 

Screenshot

Frontend

The field are simple page_parts you can access them with:

$page->hasContent('name');
$page->content('name');

Have fun
M

 
Avatar
486 posts

Nice work!

 
Avatar
36 posts

This is great! Thank you. Looking forward to implementing this into upcoming projects.

 
Avatar
36 posts

We’re having trouble getting Page Part Forms to work correctly. I followed the instructions to install it correctly, modified Frog code, etc. However, the plugin seems to break when we try to edit any of the forms you put up. Any advice on what to look out for?

 
Avatar
36 posts

I just put up a fresh install of Frog 0.9.5 and added all of the necessary plugins. Now, when I try to create a new Page Part Form, nothing comes up in the admin, but the plugin is functioning because it’s adding records to the database.

I’m hosted with Media Temple, though I’m not sure that makes a difference.

 
Avatar
36 posts

Okay, I went through the same procedure on Mosso. Fresh install. Same thing. Does not work.

The admin shows nothing when I try to add a new Page Part… sometimes even a blank screen. The database does get populated with data.

 
Avatar
70 posts

Hello all,

thanks for trying this out and sorry that the plug-in is not working for you. Please let me check some things first. I’ve redone the steps with a fresh 0.95 installation. I also tried Firefox 3.0.11 and Safari 4.0 both on a mac.

  1. download the jQuery plugin and extract it to the folder frog/plugins/jquery’
  2. download the page_metadata plug-in from github (currently 0.0.5) and extract it to the folder frog/plugins/page_metadata’
    NOTE: github adds some numbers (commit information) to the folder name. Just rename it to ‘page_metadata’
  3. download the page_part_forms plug-in from github (currently 0.0.6) and extract it to the folder frog/plugins/page_part_forms’
    NOTE: github adds some numbers (commit information) to the folder name. Just rename it to ‘page_part_forms’
  4. add the constant IN_FROG to your configuration file
  5. edit: frog/app/controllers/PluginController.php, line 75
    replace the include with an include_once
  6. edit frog/app/views/page/edit.php, line 211
    add the $page to the observer call (second argument) for view_page_edit_popup
  7. activate the plug-ins: jQuery, page_metadata, page_part_forms
  8. refresh the page with the plug-in list, there will be a new tab ‘Page Part Forms’
  9. select the tab and create a new form with ‘New Page Part Form’
  10. choose the name ‘example’ and use the following structure:
    body:
    test:
  11. select ‘save and continue editing’, on the right there should be an outline of the structure like:
  12. switch to the ‘Pages’ tab and add a new page
  13. use the name ‘Example’ as page name and switch to the sub-tab ‘More Metadata’. Select the ‘example’ form
  14. select ‘save and continue editing’, after the refresh the page should look like:

If you have completed this steps, and still have problems, please enable the ‘debug’ option in your configuration file if there is any warning with the plug-in.

I also checked it with mod_rewrite enabled and disabled.

Hope this helps
M

 
Avatar
70 posts

Hello,

ok, there is a bug, but I don’t know right now how I can fix this. The file ‘lib/Spyc.php’ must have the first char upper case.

Due to Photoshop on my mac, Adobe forced me to have a case-insensitive file system :(

UPDATE: new version is uploaded on github, also tested on external hoster :D

 
Avatar
36 posts

Thanks for looking into this M. I appreciate quick fix. Unfortunately, that didn’t seem to do it. I’ll try another clean install of everything later this evening and report back.

 
Avatar
36 posts

M, tried it again just now, followed the new instructions exactly. Still running into the same problem. Will try enabling debug options and see what comes up tomorrow.

 
Avatar
36 posts

Time for the morning update… turning off PDO in the config.php file did the trick. After two days of frustrating nothingness… Page Parts Forms works like a charm. Hopefully this helps others.

 
Avatar
70 posts

Hello everflight,

it’s not working with native PDO? Strange, but I must admit I also use the PDO-light version. I’ll look into it to find the differences.

I’m glad it worked finally, I already started to doubt myself. Maybe you would be so kind and post me your ‘structure’, so that I can see what people are doing with it (once you finished playing :D).

Have a nice working day
M

 
Avatar
36 posts

Alright, time for the stupid question. Now that I have it working on the backend, how do I get the new fields to show up on the front end? What is the code that I need to put in the layout? I’ve tried a few things, but have been unsuccessful. There is no instruction on github in the usage section. Thanks M. I appreciate the help.

 
Avatar
70 posts

Hello everflight,

check the wiki entries for the syntax, I’ll add more information if needed.

Page part form fields are simple page_parts. You can access them regularly with:

$page->hasContent('name');
$page->content('name');
 
Avatar
36 posts

Hot damn it works! Thanks for all your help. Very very useful plugin.

 
Avatar
70 posts

Hello everflight,

Hot damn it works!

thanks to the flexible interfaces of the Frog core.

Thanks for all your help. Very very useful plugin.

And BTW, the multiple values are encoded with json, you can use the PHP primitives for json to ‘split’ the values.

Have fun
M

 
Avatar
8 posts

Hi everybody!

Your plugin looks absolutely awesome, M! This is exactly, what I was about to realize :)

So, I tried to get the plugins to work and did exactly as you wrote (the second version).
Then I had exactly the same problem as everflight — his solution worked, I disabled PDO.

Now I have another problem: When entering some data into my custom page fields, these aren’t saved. I submit the new information and suddenly, everything is gone … do you have an idea, why this happens? (DEBUG is active, no errors)

 
Avatar
70 posts

Hello a.renz,

0.0.5 is buggy! Please update to the version 0.0.6.

UPDATE: github is having problems right now: ensure your have the commit: 735080f7eba227621bdb72f92af72e1cb3fec8a9

UPDATE2: version 0.0.6 fixes the PDO issues, too

M

 
Avatar
191 posts

I’ve read the explanation of page part forms five times now, but still have no idea what its function is, nor how to use it. Must be my dense brain. Can someone explain in the simplest terms under what circumstances I would use “page part forms”?

I noticed a.renz disabled PDO in order to get this plugin to work, which seems to me would potentially cause issues with Frog.

 
Avatar
70 posts

Hello redcrew,

I noticed a.renz disabled PDO in order to get this plugin to work, which seems to me would potentially cause issues with Frog.

As you can see, as of version 0.0.6 it works with and without PDO now. So there is no need to use PDOLite if not necessary. You can keep the USE_PDO with true in your config.php.

I’ve read the explanation of page part forms five times now, but still have no idea what its function is, nor how to use it. Can someone explain in the simplest terms under what circumstances I would use “page part forms”?

First of all, your don’t have to. It’s a plug-in and not part of the Frog core. If you see no use-case or benefit for it, there are chances you might not need this plug-in.

I’ll tell you my motivation for this plug-in and maybe it clarifies things a little bit.

Frog has build in support for page parts. In a pristine Frog installation you have the ‘body’ page part as default. There you can add continuous text as much as you like, but with no structural information. For example if you want to display more content on the site and the content is not part of the main content (‘body’ page part), you need another ‘container’ to store this information. E.g. attached to your root page there is the ‘sidebar’ page part that inherits the content to its children. In your presentation layer (layout and body page part) you just call $this->content('sidebar', true) to display the page part ‘sidebar’ even if this page part is not attached to the current page you are viewing. On the other hand you can overwrite the content by defining your own ‘sidebar’ page part for this page and your new content gets displayed instead. This is probably the most flexible part of the Frog CMS.

Sometimes there is the case that you want to add more structured information to the site. e.g. your want to add keywords, a custom style sheet, select pre-defined values from a list, set a rating, etc. To some point you can use the build-in metadata fields from Frog (and I strongly encourage to do so), but sometimes the fields for your particular use case is not build-in. For simple metadata I created the plug-in page_metadata, with this plug-in you can add simple ‘key-values’ fields to your page. From the admin user interface you select the tab ‘more metadata’.

Sometimes also simple metadata fields are not enough. My use-case: customer website with different products and the corresponding product descriptions. Each product is a page, there is an intro description as well as a detailed description. As a good Frog citizen I created an extra page part ‘intro’ besides the existing ‘body’ to maintain the content separately for each product. You might say: ‘hey, use an excerpt and split your main content with a regex!' —and you are right. But in my case it was simpler for the customer to have two separate textareas to maintain the two descriptions.

As part of the core user interface of Frog, page parts are organized in tabs and only allow textareas with filters —even if you just need a simpler element e.g. for a timestamp. Here comes the use of the page part forms.

Instead of creating all page parts for every product and inherit a not filled-out-warning (user forgot to fill out the second tab), I define some form fields that should be displayed instead. Due to the flexible storage of the Frog core, this form fields are stored as page parts in the back-end. This gives me the flexibility to display page parts on one page without a tab interface and to some level custom form elements (e.g. drop down, radio, etc.) based on pre-defined values. Another benefit is that in your presentation layer it makes no difference how the page part was created, you just display the content with $page->content('intro').

So why still bother your might ask? Well with page part forms you are able to define a specific back-end user interface on page level without starting to write your own plug-in.

E.g. you can create a simple event calendar. Just add the fields you need (e.g. location, price, person capacity, loudness, date, etc.) apply this form to a page and display the child pages/events at your master page (e.g. the archive page in your default Frog installation). Then you can also display only the main content (‘body’) if you display this particular page/event with additional information that is not displayed at the overview page.

Of course the plug-in can never be so flexible and feature rich as a ‘real’ plug-in solution, but it helps you to create custom content and interfaces very quickly.

Hope this outlines the purpose of this plug-in and clarifies some open questions. If there are still open questions, just post to this thread I’ll be eager to answer them ;)

M

 
Avatar
67 posts

Hi M,

Thanks for taking the trouble to provide such a detailed explanation…
Very much appreciated.

Kind Regards,
Dave Porter

 
Avatar
8 posts

Hey!
Thanks for the new version! It works beautifully now!
Once again, awesome work – thank you so much!

 
Avatar
36 posts

I just wanted to chime in again and say how incredibly useful this plugin is. Once I got it working, it’s been a real treat. From now on, I will never build a Frog based site without it. Entering content has never been more straightforward and streamlined. Maybe I’ll have to post a couple of example screenshots sometime on how I’m using it.

One thing that might be nice in the near future is to have a collection of pre-written syntax templates so people can go in and use them (as easy as copy and paste) and modify them as they see fit. Immediately, I could see some being built for things like events, product pages, etc. Might be helpful for some folks who are new to the plugin, and a time saver for those who are using it. Maybe we can all contribute some generic entries to this post? I’ll think of some.

Thank you again M for a great contribution to Frog.

 
Avatar
108 posts

I am sure this is something simple but ive gone though the entire install and its all loaded in fine. However when i try to create one it comes up with

“Page part form not found”

Any ideas anyone?

 
Avatar
70 posts

@everflight:

One thing that might be nice in the near future is to have a collection of pre-written syntax templates so people can go in and use them (as easy as copy and paste) and modify them as they see fit.

I added one in the sidebar and in the wiki, but yes we could use more.

Maybe I’ll have to post a couple of example screenshots sometime on how I’m using it.

That would be terrific! I’ll add this to the plug-in wiki.

@andytwo

However when i try to create one it comes up with “Page part form not found” Any ideas anyone?

Can you describe your environment of your installation a little bit (e.g. MySQL, SQLite, Mod_rewrite, sub-directory, etc.)? Without that searching for faults is difficult.