Send e-mail with id database

wgpereira 07 Dec, 2016
Hi!

I need to set up a form that is able to email the ID database. I tried to make the form read the database but I do not know how to do it and after send the ID.

Thanks and regards!
GreyHead 08 Dec, 2016
Hi wgpereira,

Please drag a Debugger action into the On Submit event, after your DB Read, then submit the form and post the debug - including the 'dummy emails' results here.

Note: if you are using the Easy Wizard you can turn on Debug on the Others tab in CFv4 or the Setup tab in CFv5.

Bob
wgpereira 11 Dec, 2016
[attachment=0]print.png[/attachment]Hi Bob!

Form in Brazilian Portuguese 😀


Array
(
    [chronoform] => Canal
    [event] => submit
    [comp_select] => DenĂșncia
    [comp_nome] => 
    [comp_email] => 
    [comp_subject] => Test
    [comp_message] => Just a test
    [captcha] => 
    [btnEnviar] => enviar
    [Data] => Array
        (
            [id] => 1
        )

    [ip_address] => XXX.XXX.XXX.XXX
)



Array
(
    [7] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `alxxx_cf_datatable_canal` (`comp_select`, `comp_nome`, `comp_email`, `comp_subject`, `comp_message`, `user_id`, `created`) values ('DenĂșncia', '', '', 'Test', 'Just a test', '0', '2016-12-11 13:13:15');
                        )

                )

        )

    [10] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data`.`id` AS `Data.id` FROM `alxxx_cf_datatable_canal` AS `Data`
                        )

                )

        )

    [1] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:a@a.com.br
                    [2] => Subject:Contato Compliance
                    [3] => From name:Website
                    [4] => From email: b@b.com.br
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:Website
                    [8] => Reply email: c@c.com.br
                    [9] => Attachments:
                    [10] => Body:

Mensagem enviada através do formulårio de compliance do website.

Tipo de contato: DenĂșncia
Nome: 
Email: 
Assunto: Test
Mensagem: Just a test
Endereço IP:  XXX.XXX.XXX.XXX
                )

        )

)


I'm a web designer. Simple forms I can create, but I need to create this form by sending the ID and I'm having difficulties. Would you like some Brazilian coffee? đŸ€Ł

Thanks.
GreyHead 11 Dec, 2016
Hi wgpereira,

Please put {Data.id} in the email template - you have set a Model ID so you need that in the template too:
    [Data] => Array
        (
            [id] => 1
        )

Bob
wgpereira 17 Dec, 2016
Hi Bob! Thanks!

But the form is sending the first record. I need the latest record. How can I change this?

Data Array

Array
(
    [chronoform] => Canal
    [event] => submit
    [comp_select] => Irregularidade
    [comp_nome] => 
    [comp_email] => 
    [comp_subject] => test
    [comp_message] => Just a test
    [captcha] => 
    [btnEnviar] => enviar
    [Data] => Array
        (
            [id] => 1
            [created] => 2016-11-12 18:57:53
        )

    [ip_address] => XXX.XXX.XXX.XXX
)


Debug Info
Array
(
    [7] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `alxxx_cf_datatable_canal` (`comp_select`, `comp_nome`, `comp_email`, `comp_subject`, `comp_message`, `user_id`, `created`) values ('Irregularidade', '', '', 'test', 'Just a test', '0', '2016-12-17 14:13:49');
                        )

                )

        )

    [10] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data`.`id` AS `Data.id`, `Data`.`created` AS `Data.created` FROM `alxxx_cf_datatable_canal` AS `Data`
                        )

                )

        )

    [1] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:a @[at] a [dot] com.br
                    [2] => Subject:Contato Compliance
                    [3] => From name:Website
                    [4] => From email: b @[at] b [dot] com.br
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:Website
                    [8] => Reply email: c @[at] c [dot] com.br
                    [9] => Attachments:
                    [10] => Body:

Mensagem enviada através do formulårio de compliance do website.

Ticket: 1
Tipo de contato: Irregularidade
Nome: 
Email: 
Assunto: test
Mensagem: Just a test
Data: 2016-11-12 18:57:53
Endereço IP:  XXX.XXX.XXX.XXX
                )

        )

)


Thanks!
GreyHead 19 Dec, 2016
Hi wgpereira,

Your image is hard to read but I think that you have DB Read action after the DB Save? What is that for? ChronoForms adds the new record ID to the form data after the DB Save action so you should be able to use that.

Bob
wgpereira 19 Jan, 2017
Hi Bob!

Thank you! If I remove DB Read action after the DB Save the form don't send the query. I have not yet been able to make the form send the generated ID inside the database. Where did I go wrong with Email?
<?php
// Get a db connection.
$db = JFactory::getDbo();
 // Create a new query object.
$query = $db->getQuery(true);
 // Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('id','ordering')));
$query->from($db->quoteName('#__data_Compliance'));
$query->order('ordering DESC');
 // Reset the query using our newly populated query object.
$db->setQuery($query);
 // Load the results as a list of stdClass objects.
$results = $db->lastInsertId();

print_r($results);
?>


Ticket: {Data.id}

And the data array is...
Array
(
    [chronoform] => Compliance
    [event] => submit
    [comp_select] => DenĂșncia
    [comp_nome] => 
    [comp_email] => 
    [comp_subject] => 666
    [comp_message] => 6666
    [captcha] => 
    [btnEnviar] => enviar
    [Data] => Array
        (
            [id] => 1
        )

    [ip_address] => XXX.XXX.XXX.XXX
)


It looks like the form uses the same Data Array [id] => 1. How do I get it to generate a different number for each message submission?

Regards,
GreyHead 19 Jan, 2017
Hi wgpereira,

The ChronoForms DB Save action adds the ID of the new record to the $form->data array so you have no need to add code to get it - though your code I think gets the number or records in the table rather than the last ID.

If you are seeing Data.id = 1 for all the submissions then the DB Save is probably updating the same record instead of creating a new one. Is that what is happening? If so check that your data is not being corrupted by an article ID from the form page URL.

Bob
wgpereira 19 Jan, 2017
Hi Bob! Thank you!

When I access the Connected Tables in the Form Manager, I can see all the records of the messages sent by the form. I view 17 messages sent today only. Is this data.id = 1 generated by the database or the form? Is there another way to generate an ID for messages?

Regards
GreyHead 19 Jan, 2017
Hi wgpereira,

You can use the record id if the newly created record if there is one - ChronoForms will add that to the form data after the DB Save action; or, if you want a more secure id, I have a Unique ID [GH] action that creates a short unique random string. I've sent you a PM with a link to download that.

Bob
wgpereira 19 Jan, 2017
Bob,

Thank you so much!
This topic is locked and no more replies can be posted.