Forums

DB Read action not working

royvdberg 27 May, 2019
Hi all,

I am trying to use the same form I use to save data to a database table to read and show 1 existing record. This form will be used for speakers at a conference to create a speaker profile. I want to send them an email containing a hyperlink to this form to update their data.

I put a DB Read action in the Load event, put the PHP-code in to be able to use 'id' in the URL and map this 'id' from the URL to the form hidden field 'aid'.

The form works fining for adding new data and the debuggers shows no errors when opening the form from an URL without the '&id=..' part.

However, when using the URL with '&id=1' (for example) at the end, the debugger keeps giving back error 1054 and shows the name of the Model ('sprekers').

I have tried all other Topics, manuals from previous Chronoforms versions but got stuck after several hours.

Anyone any idea how to get this to work?
healyhatman 28 May, 2019
You don't need PHP to get a value from the URL, just use {data:url_parameter_name}
Show us the URL you're using and a screenshot of your read data action.
royvdberg 29 May, 2019
Hi there,

I removed the PHP part in the condition box and set the condition to be 'aid = {data:token} where token is the final part of the URL (....&token=1). The form contains a hidden field with the aid field. Unfortunately, the form is still not loading previously saved data.

Uploading a screenshot from this post leads to an error (error in saving attachment) for jpg, png and pdf files.
healyhatman 29 May, 2019
if you're using the text / manual conditions then it's aid:{data:token}
healyhatman 29 May, 2019
Also what have you got for the data source of the field because that needs to be right as well
royvdberg 01 Jun, 2019
Hi there,

It seemed my database table got damaged: the aid column wasn't auto_increment so 3 records had an aid value of 0. I created a new table from the form and got the DB Read action to work according to the debugger:
Array
(
    [read_data16] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `sprekers`.`aid` AS `sprekers.aid`, `sprekers`.`user_id` AS `sprekers.user_id`, `sprekers`.`created` AS `sprekers.created`, `sprekers`.`modified` AS `sprekers.modified`, `sprekers`.`voornaam` AS `sprekers.voornaam`, `sprekers`.`tussenvoegsel` AS `sprekers.tussenvoegsel`, `sprekers`.`achternaam` AS `sprekers.achternaam`, `sprekers`.`emailadres` AS `sprekers.emailadres`, `sprekers`.`telefoonnummer` AS `sprekers.telefoonnummer`, `sprekers`.`organisatie` AS `sprekers.organisatie`, `sprekers`.`functie` AS `sprekers.functie`, `sprekers`.`bignummer` AS `sprekers.bignummer`, `sprekers`.`linkedin_profiel` AS `sprekers.linkedin_profiel`, `sprekers`.`foto` AS `sprekers.foto`, `sprekers`.`iban` AS `sprekers.iban`, `sprekers`.`tenaamstelling` AS `sprekers.tenaamstelling`, `sprekers`.`plaats` AS `sprekers.plaats`, `sprekers`.`voorlopige_titel_presentatie` AS `sprekers.voorlopige_titel_presentatie`, `sprekers`.`leerdoelen` AS `sprekers.leerdoelen`, `sprekers`.`literatuurverwijzingen` AS `sprekers.literatuurverwijzingen` FROM `topics_chronoforms_data_aanmelden_spreker_topics` AS `sprekers` WHERE `sprekers`.`aid` = '1' LIMIT 100;
                )

            [var] => Array
                (
                    [sprekers] => Array
                        (
                            [aid] => 1
                            [user_id] => 393
                            [created] => 2019-06-01 15:36:03
                            [modified] => 
                            [voornaam] => Peter
                            [tussenvoegsel] => 
                            [achternaam] => Spronk
                            [emailadres] => pspronk@testmail.nl
                            [telefoonnummer] => 0131234567
                            [organisatie] => Gelre ZH
                            [functie] => Intensivist
                            [bignummer] => 
                            [linkedin_profiel] => 
                            [foto] => 
                            [iban] => NL56RABO0164525347
                            [tenaamstelling] => Peter
                            [plaats] => Apeldoorn
                            [voorlopige_titel_presentatie] => Titel Peter
                            [leerdoelen] => 
                            [literatuurverwijzingen] => 
                        )

                )

        )

)
However, the form still shows empty textboxes.

Should I do anything else to have the form fields show the data that is in the array shown in the Debugger output above?
healyhatman 01 Jun, 2019
{var:read_data16.sprekers.fieldname} as the value for each field. Replace fieldname obviously
royvdberg 02 Jun, 2019
Hi there,

That was very helpfull...I got my form to work in the way I want it to.

Only one remaining question: as soon as a new form is saved, an email is sent to the email address that is documented in the form. This works great. However, inside the body of the email message I want to show a dynamic hyperlink so that the applicant can change his details.

The message is now setup like this:

Beste spreker,</p><br/>
Wij hebben uw aanmelding / wijziging gegevens in goede orde ontvangen.</p><br/>
U heeft de volgende gegevens aangeleverd:</p><br/>
{AUTO_FIELDS}</p><br/><br/>
Indien u wijzigingen wilt aanbrengen in uw gegevens kunt u hiervoor de volgende hyperlink gebruiken:<br/>
https://www.topicsinic.nl/index.php/event-pass/spreker-aanmelden&id={data:aid}<br/><br/>
Uiteraard kunt u ook contact met ons opnemen door het beantworden van dit emailbericht.<br/>

Met vriendelijke groet,</p>
het Topics in IC team

In bold I have emphasized the URL which should be sent to the applicant. Unfortunately, the {data:aid} part is not working.

Is this the consequence of aid being a hidden field in the form? And if so, do you have a proper solution to create the hyperlink without showing the aid field in the form? The latter could lead to an applicant changing the aid, thereby messing up our database.

Thanks again for your help!
healyhatman 02 Jun, 2019
You could add a verification field to the table, with the value being. {UUID:} and have that in your link instead
royvdberg 03 Jun, 2019
Hi healyhatman,

Thanx for all your help so far. I don't really understand what you mean by a verify field, but looking at the debug info again I saw the following:

Array
(
    [save_data9] => Array
        (
            [data] => Array
                (
                    [chronoform] => aanmelden-spreker
                    [event] => submit
                    [voornaam] => Peter
                    [tussenvoegsel] => 
                    [achternaam] => Testspreker
                    [emailadres] => pspronk@testmail.nl
                    [telefoonnummer] => 0612345678
                    [organisatie] => Gelre ZH
                    [functie] => Internist-intensivist
                    [bignummer] => 
                    [linkedin_profiel] => 
                    [foto] => 
                    [iban] => NL12INGB0164527354
                    [tenaamstelling] => Peter
                    [plaats] => Apeldoorn
                    [voorlopige_titel_presentatie] => Hoe word ik professor?
                    [leerdoelen] => 
                    [literatuurverwijzingen] => 
                    [aid] => 
                    [versturen] => 
                    [Itemid] => 672
                    [option] => com_chronoforms6
                    [view] => form
                    [created] => 2019-06-03 19:51:47
                    [user_id] => 0
                )

            [_success] => Gegevens met succes opgeslagen
            [log] => Array
                (
                    [0] => INSERT INTO `topics_chronoforms_data_aanmelden-spreker-topics` (`voornaam`, `tussenvoegsel`, `achternaam`, `emailadres`, `telefoonnummer`, `organisatie`, `functie`, `bignummer`, `linkedin_profiel`, `foto`, `iban`, `tenaamstelling`, `plaats`, `voorlopige_titel_presentatie`, `leerdoelen`, `literatuurverwijzingen`, `aid`, `created`, `user_id`)  values  ('Peter', '', 'Testspreker', 'pspronk@testmail.nl', '0612345678', 'Gelre ZH', 'Internist-intensivist', '', '', '', 'NL12INGB0164527354', 'Peter', 'Apeldoorn', 'Hoe word ik professor?', '', '', '', '2019-06-03 19:51:47', '0');
                )

            [var] => Array
                (
                    [voornaam] => Peter
                    [tussenvoegsel] => 
                    [achternaam] => Testspreker
                    [emailadres] => pspronk@testmail.nl
                    [telefoonnummer] => 0612345678
                    [organisatie] => Gelre ZH
                    [functie] => Internist-intensivist
                    [bignummer] => 
                    [linkedin_profiel] => 
                    [foto] => 
                    [iban] => NL12INGB0164527354
                    [tenaamstelling] => Peter
                    [plaats] => Apeldoorn
                    [voorlopige_titel_presentatie] => Hoe word ik professor?
                    [leerdoelen] => 
                    [literatuurverwijzingen] => 
                    [aid] => 5
                    [created] => 2019-06-03 19:51:47
                    [user_id] => 0
                )

        )

    [email15] => Array
        (
            [recipients] => Array
                (
                    [0] => pspronk@testmail.nl
                )

            [subject] => Nieuwe aanmelding / wijziging gegevens spreker
            [body] => Beste spreker,</p><br/>
Wij hebben uw aanmelding / wijziging gegevens in goede orde ontvangen.</p><br/>
U heeft de volgende gegevens aangeleverd:</p><br/>
<table width="100%" cellpadding="5" cellspacing="3" border="0" class="ui table"><tr><td width="30%" valign="top" align="right"><strong>Voornaam</strong></td><td width="70%" valign="top" align="left">Peter</td></tr><tr><td width="30%" valign="top" align="right"><strong>Tussenvoegsel</strong></td><td width="70%" valign="top" align="left"></td></tr><tr><td width="30%" valign="top" align="right"><strong>Achternaam</strong></td><td width="70%" valign="top" align="left">Testspreker</td></tr><tr><td width="30%" valign="top" align="right"><strong>Emailadres</strong></td><td width="70%" valign="top" align="left">pspronk@testmail.nl</td></tr><tr><td width="30%" valign="top" align="right"><strong>Telefoonnummer</strong></td><td width="70%" valign="top" align="left">0612345678</td></tr><tr><td width="30%" valign="top" align="right"><strong>Organisatie</strong></td><td width="70%" valign="top" align="left">Gelre ZH</td></tr><tr><td width="30%" valign="top" align="right"><strong>Functie</strong></td><td width="70%" valign="top" align="left">Internist-intensivist</td></tr><tr><td width="30%" valign="top" align="right"><strong>BIG-nummer&nbsp;<i class="icon info circular blue inverted small" data-hint="Indien u accreditatie-punten voor dit congres wilt ontvangen, dient u uw BIG-nummer in te vullen"></i></strong></td><td width="70%" valign="top" align="left"></td></tr><tr><td width="30%" valign="top" align="right"><strong>Linkedin profiel</strong></td><td width="70%" valign="top" align="left"></td></tr><tr><td width="30%" valign="top" align="right"><strong>Foto&nbsp;<i class="icon info circular blue inverted small" data-hint="Het liefst ontvangt Topics in IC een profielfoto voor gebruik op de website en in het programmaboekje.
Wilt u liever geen profielfoto aanleveren? Dan is een foto die past bij uw lezing ook een optie."></i></strong></td><td width="70%" valign="top" align="left"></td></tr><tr><td width="30%" valign="top" align="right"><strong>IBAN</strong></td><td width="70%" valign="top" align="left">NL12INGB0164527354</td></tr><tr><td width="30%" valign="top" align="right"><strong>Tenaamstelling</strong></td><td width="70%" valign="top" align="left">Peter</td></tr><tr><td width="30%" valign="top" align="right"><strong>Plaats</strong></td><td width="70%" valign="top" align="left">Apeldoorn</td></tr><tr><td width="30%" valign="top" align="right"><strong>Voorlopige titel presentatie</strong></td><td width="70%" valign="top" align="left">Hoe word ik professor?</td></tr><tr><td width="30%" valign="top" align="right"><strong>Leerdoelen&nbsp;<i class="icon info circular blue inverted small" data-hint="Voor verpleegkundige accreditatie van Topics in IC is het nodig dat sprekers leerdoelen opstellen voor hun presentatie. Deze kunt u ook in een later stadium nog doorgeven."></i></strong></td><td width="70%" valign="top" align="left"></td></tr><tr><td width="30%" valign="top" align="right"><strong>Literatuurverwijzingen&nbsp;<i class="icon info circular blue inverted small" data-hint="Voor verpleegkundige accreditatie van Topics in IC is vermelding van minimaal 2 literatuurverwijzingen noodzakelijk. Deze kunt u ook in een later stadium nog doorgeven."></i></strong></td><td width="70%" valign="top" align="left"></td></tr></table></p><br/><br/>
Indien u wijzigingen wilt aanbrengen in uw gegevens kunt u hiervoor de volgende hyperlink gebruiken:<br/>
https://www.topicsinic.nl/index.php/event-pass/spreker-aanmelden?chronoform=aanmelden-spreker&id=<br/><br/>
Uiteraard kunt u ook contact met ons opnemen door het beantworden van dit emailbericht.<br/><br/>
Met vriendelijke groet,</p>
het Topics in IC team
            [from_name] => Topics in IC
            [from_email] => info@topicsinic.nl
            [reply_name] => Topics in IC
            [reply_email] => info@topicsinic.nl
            [cc] => Array
                (
                    [0] => info@topicsinic.nl
                )

            [result] => de Email is met succes verstuurd.
            [var] => 1
        )

    [upload12] => Array
        (
            [path] => ../images/topics/sprekers/
            [var] => 
        )

)

So on saving the record to the database, the field 'aid' is empty, which is logical because the aid is set by the database itself. So in the 'data' array the aid field is empty. However, after saving the record a new array is created, which seems to have the name 'var'. In this data array the aid field actually shows the id the database gave to the new record.

It is THIS aid value that I want to use in the email-action in my form. When I use {data:aid} or {var:aid} or {var:sprekers.aid} in my email-action nothing is shown in the email sent to the user.

Any idea how to get this aid item, which obviously exists in the array, into my email message?
This topic is locked and no more replies can be posted.