Forums

Two Forms one Database?

juntaar 15 Apr, 2009
Hi All,

I've set up a form for adding users and details to a database. I've then added a connector to list the members in brief (Member List), and a separate connector to view detail info about one member (Member Details). The separate details form has an edit record function, which can be used to update all fields.

Now I want to add another form to fill or edit only two fields of each member (not all of them) called "Member Payment Details", fields that will get updated by this special form from time to time as we record if a member has paid their membership fees.

I tried adding a link to a new, third connector using the:

<a href="http://*.com/member-payment.html?connectionname=MemberPayment&task=editrecord&cids=<?php echo $row->cf_id; ?>" title="Membership Payment">


Property from within my Member List connector. This sort of works (its a bit of a dirty solution to link straight to the edit record link), and I can save data into the database (update existing records) but it has two major draw backs.

1) There is no redirect property for the connector. Meaning after I save the data it always redirects to the main page for that connector (meaning I can't distinguish between submitted and cancelled form).

2) Sometimes (for new records it seems) I get a permissions error: Error 2 after clicking the link. This seems to go away (unconfirmed) either when I manually go to the connector, but I cannot be sure yet, it may also be to do with records that don't have data for these two fields.

The other method I wanted to try is using a form rather than a connector to achieve the same goal, but I worry that using a form will create a new entry (increment the cf_id) rather than updating existing ones. I'm also not sure how to go about it because there is no WHERE input available for forms (only on the connector).

Can anyone provide any insight as to what is the best approach to achieve this functionality?
GreyHead 15 Apr, 2009
Hi Juntaar,

Not sure about the ChronoConnectivity questions but a ChronoForms Form will update a record provided that the data you are saving includes an existing primary key (usually the user_id).

Bob
juntaar 15 Apr, 2009
Hi Greyhead,

Thanks for the reply. If thats the case I will definitely use a form instead of a connector.

Using phpMyAdmin I found that the database is using cf_id as the primary key.

Just wondering, how can I ascertain the primary key for a given user on form generation? Presumably I have to query the database before generating the form or can I just pass it as a variable in php (which is probably easier for me😛 similar to the last issue you helped me resolve)?

After I have the key, do I simply put a hidden input field with the cf_id in my form, and chronoform will take care of the rest?

Something like this?:

<input type="hidden" name="cf_id" value="<?php echo $row->cf_id; ?>" />


Cheers

Juntaar
GreyHead 15 Apr, 2009
Hi Juntaar,

I'd probably look the record up in the Form HTML and use the other results to pre-populate any form fields, and add the cf_id in a hidden field as you suggest.

Bob
juntaar 15 Apr, 2009
Hi Greyhead,

I've sorted the hidden field out, it works great, but am curious as to whether I can use chronoforms calls to query the db or do I have to manually make a connection (ie. mysql_connect, select, query) from within the form?

Thanks,

Juntaar
Max_admin 16 Apr, 2009
Hi Juntaar,

chronoforms will not query the data table by default, it queries only the forms table and you can use the form variables if you need, but not the data table values, if you need to use the data tables values then you need a different query preferably done the Joomla way :


$query = "SELECT * FROM `#__table` WHERE `id` = '".$id."' ORDER BY id";
$database->setQuery( $query );
$data = $database->loadObjectList();


Is this what you are looking for ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
juntaar 16 Apr, 2009
Hi Max,

Thats exactly what I wanted to do - thanks!

Cheers,

Juntaar
This topic is locked and no more replies can be posted.