Form Edit from CCv5 - update vairables in ACYmailing

Dtorr1981 13 May, 2015
Hi guys,

I have a form which updates two tables and add user details to ACYmailing and subscribes the user to the list, i then have a CC table which lists the data from these 2 tables. I have added an edit to the list which opens another chronoform (the form has additional variables that can be updated, but are still included in the 2 original tables), obviously i would like this Edit form to also edit the details in ACYMailing as well as the 2 tables.

The code i have utilised to add the user to ACYMailing is:

<?php 
 include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_acymailing'.DS.'helpers'.DS.'helper.php');
 $myUser = new stdClass();
 $myUser->email = strip_tags(JRequest::getString('email')); //email field.
 $myUser->name = strip_tags(JRequest::getString('fname')); //first name field
$myUser->class = strip_tags(JRequest::getString('class')); //class field.
$myUser->school = strip_tags(JRequest::getString('school')); //school field.
$myUser->t_date = strip_tags(JRequest::getString('t_date')); //taster date field.
$myUser->t_num = strip_tags(JRequest::getString('t_num')); //Phone number field.
 $subscriberClass = acymailing_get('class.subscriber');

 $subid = $subscriberClass->save($myUser);
 
 
$subscriberClass->sendConf($subid); //we send the confirmation email... only if needed based on the current user status and the option from the Acy configuration page.
 
 $subscribe = array(3); //Specify here the ID of your lists separated by a comma, in this example the user will be subscribed to lists IDs 3,4 and 5.
 
 $newSubscription = array();
 if(!empty($subscribe)){
 foreach($subscribe as $listId){
 $newList = array();
 $newList['status'] = 1;
 $newSubscription[$listId] = $newList;
 }
 } 
$subscriberClass->saveSubscription($subid,$newSubscription);
?>


Can anyone advise what i need to change to make this update the user rather than create a new one? Also, which css files does chronoconnectivity use for the table view, as the text is huge and i cant identify where the css is coming from so i can override it.

Thanks in Advance
Donna
GreyHead 14 May, 2015
Hi Donna,

That's really a question for AcyMailing. I don't have it installed at the moment but I'd guess that if you set the current user id with something like
$myUser->email = $id;
should force an update???

Bob
Dtorr1981 14 May, 2015
Hi Bob,

thank you for your reply, after much fiddling i seem to have overcome my initial issue....but now have the problem that new records are being submitted rather than updated. I've read some of the other posts regarding this matter and i'm still confused. Basically, my two tables are connected by primary key ('id') in the _users table and foreign key ('user_id') in the _lead_info table. Thus when i submit the form i want to update the record where the user_id matches the id from the users table....is this easy to achieve, i have no idea where to start....

Thanks in advance
Donna
GreyHead 15 May, 2015
Hi Donna,

If you use the ChronoForms DB Save it relies on the record primary key. If there is one in the data to be saved and it exists in the table then the record will be updated; otherwise a new record is created.

There are a couple of possible problems with your data.

a. If 'id' is used as the primary key then there is a potential for confusion with other 'id' entries in the $form->data[''] array - and in particular with an article id if the form is on an article page.

b. You want to identify the record from the user_id column which presumably isn't the primary key for that table. For this you have two choices:

+ Use the ChronoForms DB Save action but get the primary key value matching the user_id.

+ Use a Custom Code action with a hand-coded MySQL query using . . . WHERE `user_id` = {$form->data['user_id']}

Bob
Dtorr1981 15 May, 2015
Hi Bob,

Fortunately there aren't any articles involved in this instance. I basically have an add on to the standard joomla user table where the foreign key is user_id -->id in the joomla users table. I am also updating the users in ACYmailing if there details have changed.

However, it is only in the additional information table (lead_info) where duplicates are being posted. Can you advise how i would implement this in the DB save action? Or point me in the correct direction.

Thank you in advance.

Donna
GreyHead 18 May, 2015
Hi Donna,

I'm sorry there isn’t enough information here to start to help.

What is the structure of the table you want to save to? How are you getting the record ID that you need to update? How are you trying to save to the data?

Bob
Dtorr1981 20 May, 2015
Hi Bob,

I was hoping i could use the user_id field as this is the foreign key? I'm guessing i need some code which identifies the record based on the user_id passed from the form? Is that correct?

The data is saved in a DB save action in side a submit action, which has the lead_info table in it.

Apologies for being such a newbie to all this.

Best Regards
Donna
GreyHead 25 May, 2015
Hi Donna,

I'm still not seeing this clearly :-(

I probably don't know enough about ACYMailing and how their method works.

To save data to a database table from ChronoForms there are two choices.

a. You can use the ChronoForms DB Save action. This relies on the Primary Key of the table to be updated; if that exists then the record is updated; if there is no value in the form data or it doesn't exist then a new record is created.

b. You can use a Custom Code action and add your own MySQL query - I recommend that you use the Joomla! methods for this. With this approach you can use any normal MySQL WHERE clause to update a record.

Bob
Dtorr1981 26 May, 2015
Hi Bob,

What do you mean by ' This relies on the Primary Key of the table to be updated; ' if you can explain how i ensure this is the case i should be ok, I already have the primary key stored in a hidden control on my form for both the users table and the leadinfo table.

Best Regards
Donna
GreyHead 26 May, 2015
HI Donna,

If the Primary Key column for your table is say cf_id. Then if there is a value for cf_id set in the form data e.g. $form->data['cf_id'] = 99 then record 99 will be updated if it exists. If it doesn’t exist or there is no value set then a new record is created.

If you are using a Model ID say 'model_id' then $form->data['model_id']['cf_id'] will be checked and the data to be saved all needs to be in the form $form->data['model_id']['column_name']

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