Custom Form for Multiple Tables

A place for users and developers of the Xataface to discuss and receive support.

Postby roginald » Thu Jan 11, 2007 5:08 pm

I apologize if this has been brought up before. I have a working dataface applications with several m-m relationships. I have created a form outside of dataface, just as a mockup for layout purposes. I see how one can use the dataface quickform tool to generate input forms on a per table basis. Is it possible to customize it such that i can allow users to enter in all of the information into a single form that will then update each table accordingly using a dataface generated form?

If not, what would be the best route to send the data from my form to dataface for processing, if that is feasible?
roginald
 
Posts: 24
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jan 12, 2007 1:32 pm

Hi Roland,

While there is no silver bullet strategy for this currently, there are a number of ways that you can achieve this - and it will depend a little bit on what you mean by "send the data to dataface for processing".

Strategy 1: Create a dummy relationship and then display a new related record form.

Dataface has the ability to generate forms to add records to a relationship. A relationship is basically an SQL query that can span over multiple tables. If you don't want the relationship to appear in the related tabs for your table, you can set the action:visible property of the relationship to 0. E.g. in the relationships.ini
Code: Select all
[customform_relationship]
__sql__ = select * from people ppl inner join publications pub on ppl.personid=publications.ownerid
action:visible = 0

To access a form to add new records to this relationship (it will contain all fields form people and publications tables), you would enter the url:
http://yourdomain.com/yourapp/index.php?-table=people&-action=new_related_record&-relationship=customform_relationship

(This assumes that the relationships.ini file above was for the "people" table).

The limitation of this strategy is that you can only add new records with this form - you can't edit existing records.

Strategy 2: In MySQL 5, create a view with all of the fields you need in your form - and then just add new records to this view from dataface.

You have to make sure that all of the primary keys are included in the view - and the fields.ini file must tell dataface which fields are keys (because it can't pick it up for views) by adding:
Key = PRI
to all columns that should be part of the primary key.

Strategy 3: Create a dummy table with columns for each field you want on your form, and use the afterInsert(), afterSave(), or afterUpdate() triggers to update the target tables whenever this table is updated.
e.g.
Code: Select all
function afterInsert(&$record){
    $people_rec = new Dataface_Record('people', array());
    $people_rec->setValues($record->getValues());
    $people_rec->save();
   
    $publications_rec = new Dataface_Record('publications', array());
    $publications_rec->setValues($record->getValues());
    $publications_rec->save();
}


There are probably other strategies but this should give you something to chew on.

Best regards

Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 27 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved