Forums

Fill form with Db read and Url Token

florianprm4865 25 Jul, 2016
Hi Everyone,
I'm passed out with an issue i'have to faced, let me first present the context, and what i want to do.
I wish to make a student plateform to do survey and share job opportunities for graduated that have a work position.
The workflow will be as followed
1) the administrator (teacher) fill the data base with CSV fille. (The UUID is autogenerate from mysql trigger function NEW.UUID)
[attachment=0]db.PNG[/attachment]

2) a mail is send to each member 'MAIL' with a link containing the 'UUID',
The link will have this form :
'Joomla_site'/index.php?option=com_chronoforms5&chronoform='form name'&token=5500f6e8-5263-11e6-85bd-fa163efc.
3) when cliking the link, user will be redirected to the form that show form field pre-filled from database .
[attachment=1]form designer.PNG[/attachment]


4) user will update some value (new job or new position)
5) submit button upload the db with new value.

curently form works to enter new value.
Now I have create a db read (on load and before render)
with following code in parameter.
<?php 
$menu_id = JRequest::getVar('Itemid');
include (JPATH_SITE.'/components/com_chronoforms5/includes/menu_ids.php');

$form->data['token']= $menu_ids[$menu_id];
      return array('UUID' => '$menu_ids[$menu_id]);
?>


When executing the url with the following token '5500f6e8-5263-11e6-85bd-fa163efc' as option, the debugger can read db and return me following result.

Data array:
Array
(
    [option] => com_chronoforms5
    [chronoform] => suivi1
    [token] => 5500f6e8-5263-11e6-85bd-fa163efc
    [Data2] => Array
        (
            [0] => Array
                (
                    [ID] => 1
                    [UUID] => 567fe140-5260-11e6-85bd-fa163efc
                    [UPDATED] => 2016-07-25 14:07:33
                    [NOM] => Monnom
                    [PRENOM] => monprenom
                    [MAIL] => monmail@gmail.com
                    [DATE_NAISSANCE] => 2016-01-03
                    [dropdown] => NA
                )

            [1] => Array
                (
                    [ID] => 2
                    [UUID] => 5500f6e8-5263-11e6-85bd-fa163efc //this is the token passed as parameter 
                    [UPDATED] => 0000-00-00 00:00:00
                    [NOM] => PEREME
                    [PRENOM] => Florian
                    [MAIL] => 
                    [DATE_NAISSANCE] => 2010-05-19
                    [dropdown] => liste2
                )

            [2] => Array
                (
                    [ID] => 3
                    [UUID] => 91c7f33a-5263-11e6-85bd-fa163efc
                    [UPDATED] => 0000-00-00 00:00:00
                    [NOM] => Dupont
                    [PRENOM] => jacque
                    [MAIL] => jcdupont@gmail.com
                    [DATE_NAISSANCE] => 2012-08-29
                    [dropdown] => liste3
                )

            [3] => Array
                (
                    [ID] => 4
                    [UUID] => d42bb2bf-5263-11e6-85bd-fa163efc
                    [UPDATED] => 0000-00-00 00:00:00
                    [NOM] => Dupont
                    [PRENOM] => jacque
                    [MAIL] => jcdupont@gmail.com
                    [DATE_NAISSANCE] => 2012-08-29
                    [dropdown] => liste3
                )

        )

)
Array
(
)


Errors:
Array
(
)

Debug Infos
Array
(
    [2] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data2`.`ID` AS `Data2.ID`, `Data2`.`UUID` AS `Data2.UUID`, `Data2`.`UPDATED` AS `Data2.UPDATED`, `Data2`.`NOM` AS `Data2.NOM`, `Data2`.`PRENOM` AS `Data2.PRENOM`, `Data2`.`MAIL` AS `Data2.MAIL`, `Data2`.`DATE_NAISSANCE` AS `Data2.DATE_NAISSANCE`, `Data2`.`dropdown` AS `Data2.dropdown` FROM `suivi` AS `Data2`
                        )

                )

        )

)
.

So now i'm blocked, and have 2 questions:
[list]Is the actually process, right ? (I want to get all data comming from user with specific UUID).
How to fill my form fields with these values as default?[/list]
Thanks a lot for your time and knowledge
GreyHead 25 Jul, 2016
1 Likes
Hi florianprm4865,

A bit hard to tell but it looks as if you need to add an entry in the Conditions Box of the DB Read action to select the record with the correct ID, and you want the DB Multi setting to be NO, and probably Data Path to be empty.

I can't work out what the code with the Menu IDs is doing?

Bob
florianprm4865 08 Aug, 2016
Hi bob thanks for you reply,
effectively, set the no multi record, with the condition:
<?php
return array('UUID' => JRequest::getVar('token'));
?>

allow me to store a unique array in my model ID, coming from the "token" url.

Now i'have a second issue! (promise it should be the last🙂 )
I have in my form some dropdown fields.
[list] . First I enable dynamic data to populate field option from my DB[/list]
[list]. Second I set default field value with my "tokenized" result {mytokenmodelid.MYFIELD} [/list]
Both worked fine.
When user received his email with url, he will be redirected to the form with the right default value, and a list defined options.
BUT THE PROBLEM IS !:
If the user is satisfied with the default value he won't change it (well it exactly the purpose),but when he submit his form, the array return an empty result for this dropdown item.
so I would like to define a condition, like, if array field is empty, dump this field and don't save to DB, so i will keep the old data for this specific entry, and update the other one.
I tryed many many codes in DB save condition, and no one works.
can you please help me.
Thanks
GreyHead 12 Aug, 2016
Hi florianprm4865,

For the first point - CF automatically loads any variables form the URL into the form data so you should be able to use
<?php
return array('UUID' => $form->data['token']);
?>


For the second one you can use code like this
<?php
if ( empty($form->data['xxx']) ) {
  unset($form->data['xxx']);
}
?>

This will prevent an empty value being saved to the database and over-writing an existing one.

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