Forums

How to read and write (or change) fields of a form db table

haffpaff 01 May, 2016
Hi!

Originally I would like to send the uniq_id as a key within my email to the form submitter.

I found this http://www.chronoengine.com/forums/posts/t94981/p326799/chrono-forms-v5-unique-id.html#p326799 article and built a small form like this

The code is
<div class="form-group gcore-form-row" id="form-row-email"><label for="email" class="control-label gcore-label-left">E-Mail</label>
<div class="gcore-input gcore-display-table" id="fin-email"><input name="email" id="email" value="xxx@zzz.yyy" placeholder="" class="validate['required','email'] form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" /></div></div><input name="uniqueid" id="uniqueid" value="" type="hidden" class="form-control A" /><div class="form-group gcore-form-row" id="form-row-senden"><div class="gcore-input gcore-display-table" id="fin-senden"><input name="senden" id="senden" type="submit" value="Senden" class="btn btn-default form-control A" style="" data-load-state="" /></div></div>


The form setup is .

The custom code is
<?php
  $uid = $form->data['cf_id'] + 1126;
  $uid = sprintf('%04d', $uid);
  $uid = 'MRIT-ID_'.$uid;
  $form->data['uniqueid'] = $uid;
?>


And the email-template is
<table>
<tr><td>E-Mail</td><td>{email}</td></tr>
<tr><td>uniqueid</td><td>{uniqeid}</td></tr>
</table>
.

The debugger output is
Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => tst
    [event] => submit
    [Itemid] => 
    [email] => xxx@zzz.yyy
    [uniqueid] => MRIT-ID_1166
    [senden] => Senden
    [cf_id] => 40
    [ip_address] => <CENSORED>
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [11] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `sx7qh_cf_tst` (`email`, `uniqueid`, `user_id`, `uniq_id`, `created`) values ('xxx@zzz.yyy', '', '0', '3aaa00c7bb1faea70452d379518cea350eecdc00', '2016-05-01 11:22:45');
                        )

                )

        )

    [0] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:xxx@zzz.yyy
                    [2] => Subject:tst
                    [3] => <CENSORED>
                    [4] => <CENSORED>
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td>E-Mail</td><td>xxx@zzz.yyy</td></tr>
<tr><td>uniqueid</td><td></td></tr>
</table><br /><br />IP: >CENSORED>
                )

        )

)


and the correspondig email is
E-Mail	xxx@yyy.zzz
uniqueid	


IP: <CENSORED> 


What is wrong?

I'd also like to do something like this in the custom code:

uniqueid is set to uniq_id (which was generated by chrono forms/joomla/mysql), but

$form->data['uniqueid'] = $form->data['uniq_id'];

does not work.


Any help is very much apreciated.

Thanks in advance
GreyHead 01 May, 2016
Hi haffpaff,

In the email template you have {uniqeid} but the input name is uniqueid.

The code you have to re-save the id form the database should work OK
$form->data['uniqueid'] = $form->data['uniq_id'];
but the unique ID generated in the table is very long (and just possibly may not be unique).

Bob
pj1907 14 Oct, 2016
Hi,

The instruction:

$form->data['uniqueid'] = $form->data['uniq_id'];

is not actually writing into the database (checked via phpmyadmin).
What additional code do I have to add to the custom code, in order to store 'MRIT-ID_1166' into a database field?
Something like INSERT INTO or UPDATE ?
Any help?

Thanks.
Piergiotgio
GreyHead 14 Oct, 2016
Hi pj1907,

That is an answer to a specific query, it won't necessarily work with any other form

What exactly do you need to do?

In general if you have an item of form data then you can save it using a DB Save action in your form. If the column name is the same as the form input name then that should work smoothly.

Bob
pj1907 15 Oct, 2016
Hi Bob,

Thank you for your answer.
I need to provide a unique 'card number' to anyone who fill and send a form I have created with Chronoform V5.
Following this thread, http://www.chronoengine.com/forums/posts/t94981/p326799/chrono-forms-v5-unique-id.html#p326799 and also the current one, I included the following custom code after the db save action and before the send email action:

<?php
    $uid = $form->data['id'];
    $uidpre = rand (100, 200);
    $uidpost = rand (100, 200);
    $uidfull = $uidpre.$uid. $uidpost;
    $uid = sprintf('%011d', $uidfull);
    $form->data['uid'] = $uid;
    $form->data['card'] =  $form->data['uid'];
    ?>


That's working great and the sent email includes the 'pseudo random' card number generated above.

Anyway, as additional step I would also like that the 'card number' generated is written back into the database in the 'card' field, for later purposes.
Because the the db save action is run before the custom code generation, I suppose that there should be another db save action, to be included into the custom code or a part from that, in order to save the newly generated 'card number' into the db. I'm I right?

Hope I was clear with my question... my english is quite rough. Sorry for that :-)

PIergiorgio
GreyHead 15 Oct, 2016
1 Likes
Hi pj1907,

If you need to have the record id included in the string then, yes you'd need to have a second save.

If you don't then you could generate the random string before the first DB Save.

Bob

PS I do have a custom action that will create random unique alpha-numeric strings if you need it.
pj1907 15 Oct, 2016
Hi Bob,

Worked as a charm.
I simply included into the form, as you suggested, a second Db save action after the custom code and before the send email action ;-)

For the moment what I need is a sort of mixed autoincrement / random code where the autoincrement number (obteined from the Id field) is included into the full card number.
Anyway thank you for your offer. As an option I could consider a full unique random aIpha-numeric string. So if it's not a problem for you to share your string, that would be great.
Thank you again.
Have a good weekend.

Piergiorgio
GreyHead 16 Oct, 2016
1 Likes
Hi Piergiorgio,

I have sent you a PM with a download link, The action doesn't currently allow you to include an input value in the string - though you could do that with a Custom Code action using some PHP to add it in.

Bob
pj1907 17 Oct, 2016
Hi Bob,

Thank you very much!

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