PHP Classes

Master form-subform queston

Recommend this page to a friend!

      PHP Forms Class with HTML Generator and JavaScript Validation  >  PHP Forms Class with HTML Generator and JavaScript Validation package blog  >  How to Show Google Ma...  >  All threads  >  Master form-subform queston  >  (Un) Subscribe thread alerts  
Subject:Master form-subform queston
Summary:How to have a multiple-line subform below a master form
Messages:9
Author:Harvey P. Morgan
Date:2006-10-10 19:53:58
Update:2006-10-26 16:45:08
 

  1. Master form-subform queston   Reply   Report abuse  
Picture of Harvey P. Morgan Harvey P. Morgan - 2006-10-10 19:53:58
Manuel,

I'm working on a Web site to display photos of churches in this part of France.

And I'm ready to start entering data about the towns the churches are located in. For this I envisage a Web page that has at the top what I could call a master form. It has a several lines of data about the town, its name, which political subdivision it belongs to, etc. This data is already in the database, having been imported from a government source. There is nothing to enter or edit here.

Beneath the master form I'd like to have a subform with potentially multiple lines. Each line would be devoted to a characterisitic of the town. Sample characteristics: history of the town, whether it was a bastide, whether it was on the Chemin de St-Jacques, etc. I would like to be able to add, edit, and delete these lines.

There is a lookup table that defines what characteristics towns are allowed to have.

When I invoke the page, it would have the master data about the town at the top and any existing characteristics displayed beneath and some way to add/edit/delete characteristics as I uncover relevant data.

I have the master form part of this page defined and that works quite nicely. What I cannot work out is how to add the multi-line subform beneath.

Help!

I will cheerfully answer questions if the above is not clear.

Thanks,
Harvey

  2. Re: Master form-subform queston   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-10-10 21:20:14 - In reply to message 1 from Harvey P. Morgan
What you want is a little complicated but can be done with a some patience.

Your form is not fixed. It will may have a variable number of lines of fields.

The lines will have similar fields for different characteristics. So you need to loop over the characteristics list and add groups of fields with different names for each characteristic, like: edit_characteristic_x, delete_characteristic_x, edit_characteristic_y, delete_characteristic_y, and so one.

When you process the form, you need to use the WasSubmitted function of the form class to determine if one of those submit buttons was used, and if so, which was it. Then you need to decode the name of the submit button that was used to figure what action you will take.

You may or may not need to use sub-forms. Sub-forms may be needed only if you want to perform validation on a different subset of fields depending on the submit button that was used.

  3. Re: Master form-subform queston   Reply   Report abuse  
Picture of Harvey P. Morgan Harvey P. Morgan - 2006-10-11 07:23:19 - In reply to message 1 from Harvey P. Morgan
I was afraid that would be the answer. I'd been thru the documentation and wasn't able to find an easy way to do header-detail forms.

And yet this is a very common situation in the business application world. I can't think of how many data entry forms I've worked on that called for entry of a header record into the master part of the form, followed by entry of detail records into the subform below. The header record typically has who, when, for whom; the detail has what and how many. A few examples: Sales Orders, Purchase Orders, Material Receipts, Payment Entry, and so on.

I described briefly how I envisaged the form to handle data entry for a town. Actually it's more complicated than that. Not only does a town have characteristics, it also has churches. On the one form, perhaps using a tabbed form, I'd also like to enter data on the churches in a town. And the church record has several different detail records associated with it: its characteristics (age and architectural style), affiliation, physical state, and photos. And the photo record has various detail records associated with it: camera, photo size, photographer. So in reality the database has four levels of header-detail-subdetail-subsubdetail records. I'm tempted to revert to old habits and create a desktop application to enter the data into my database rather than enter the data over the Web.

Perhaps I'm going about this the wrong way, looking to reproduce on the Web a common way of doing data entry in desktop applications. Is there a better way to handle header record-detail records entry on the Web than what I'm used to?

Harvey


  4. Re: Master form-subform queston   Reply   Report abuse  
Picture of Matías montes Matías montes - 2006-10-11 12:39:27 - In reply to message 3 from Harvey P. Morgan
I'm not sure I quite follow exactly what it is that you are attempting to do, but it seems that you have to input several subsets of data. Each of which will affect what data can or cannot be input in the others.

My approach to this kind of issue would be to divide the subsets of data in different steps and prepare a multi-stepped form.
So you would use diferent form scripts for each of the form steps and make a much clearer code. It is fairly simple, instead of saving the data in your database on submit of each step you could save it in a session variable, temporary file or temporary table, when all the steps have been completed and confirmed, you save the data in the db and delete the temporary data.
It is the typical web approach for this kind of forms you seem to be attempting to do. A typical example would be a checkout process form in an eCommerce application.

Hope this will help you


  5. Re: Master form-subform queston   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-10-12 00:27:27 - In reply to message 3 from Harvey P. Morgan
I think that if what you want follows the same pattern consistently, you can develop a plug-in for the class that generates and validates all your form detail sections using a simple form definition.

For instance, the CAPTCHA validation plug-in takes a few parameters and creates all the inputs along with additional HTML and Javascript to perform what it needs to do.

Once the initial investment on the development of the plug-in is done, your application development becomes much faster and pleasant.

The forms class documentation comes with detailed explanations on what you need to do to develop a custom plug-in. Feel free to ask more questions if want to pursue that route and you are not sure how to solve details of your problem.

  6. Re: Master form-subform queston   Reply   Report abuse  
Picture of Harvey P. Morgan Harvey P. Morgan - 2006-10-14 17:26:29 - In reply to message 5 from Manuel Lemos
Matias and Manuel,

Thank you for your thoughtful responses.

Matias, I like inputting directly to a database. That way I can take advantage of the built-in error checking (referential integrity) of the database--makes the programming a little simpler.

Manuel, I confess I'm not up to doing a plug-in. The investment in time is more than I think I want to undertake right now. I've got information on over 500 towns to enter, and at the moment I have photos of 250 churches that I need to enter info about.

So I've gone ahead and created a Microsoft Access front-end to my MySQL database and have started entering data. Access makes easy the creation of the form-subform data entry scheme I talked about. It may be a question of old dogs and old tricks.

Manuel, I have a Metabase question that I'll pose over at the Metabase forum.

Thanks again to both of you for your input.

Harvey

  7. Re: Master form-subform queston   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-10-14 20:50:28 - In reply to message 6 from Harvey P. Morgan
No problem.

I confess that I have not quite understood what kind of user interface you want to build to update your database.

Maybe it is a simple scaffold interface for adding new records to tables. I intend to develop an AJAX plug-in to implement such kind of user interface.

If it is not that, it may be useful if you can show some screenshots of your Access based user interface, so we can understand better what you mean.

  8. Re: Master form-subform queston   Reply   Report abuse  
Picture of Harvey P. Morgan Harvey P. Morgan - 2006-10-26 15:00:39 - In reply to message 7 from Manuel Lemos
Manuel,

I confess I don't see how to post a screenshot to the forum. My Access app is up and working quite nicely. I'd be happy to send screenshots to make clear what I'm talking about.

Harvey

  9. Re: Master form-subform queston   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2006-10-26 16:45:08 - In reply to message 8 from Harvey P. Morgan
Currently there is no way to attach files to forum posts.

You may want to try uploading to the photos section of the forms mailing list:

tech.groups.yahoo.com/group/forms-d ...