Forums

what trigger Auto Detect in write action? ​

rslyra 12 Mar, 2020
what trigger Auto Detect in write action?

I know that Auto detect is triggered by the key value of tha table, but where CHF6 check it?

I think about two options.

1 - field value in Save block
2 - a hidden field in form that have the key value field name.
GreyHead 12 Mar, 2020
Hi rslyra,

ChronoForms checks for it in the form data - you can see what is there by using the form Debugger. It could be added as you suggest, or from data saved to the User session or, . . .

Bob
rslyra 12 Mar, 2020
Hi GreyHead.

Two questions

To be in the form data I need to create a hidden field where ID is the field name, right?

If the key value is zero, this should be a insert, right?
GreyHead 12 Mar, 2020
Hi rslyra,

The name should match the id column name in the database table.

The insert key value should be Null, or better there should be no id data item.

Bob
rslyra 13 Mar, 2020
Hi. 

I decided to start all over again, from start. A clean start, as they say.

I deleted all form test I had and start a new one.

===TABLE===========================================

CREATE TABLE `cat5_org` (
`org_id` int(11) NOT NULL,
`org_sigla` varchar(50) NOT NULL,
`org_nome` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

ALTER TABLE `cat5_org` ADD PRIMARY KEY (`org_id`);
ALTER TABLE `cat5_org` MODIFY `org_id` int(11) NOT NULL AUTO_INCREMENT;

===Form, from beginning=================

New form => empty form

Settings
Title: orgaos
Alias: orgaos
Debug: on
Multi page Form: off (otherwise it keeps showing the same data over and over)

pages/Views
new text field/General
Label: Sigla
Name: org_sigla
Value: {var:read_data3.Data3.org_sigla}

new text field/General
Label: Nome
Name: org_nome
Value: {var:read_data3.Data3.org_nome}

new Button/General
type: submit

new Hidden field/General
name: org_id
Value: {var:read_data3.Data3.org_id}

pages/Actions/load
new Read Data (read_data3; model name: Data3)
Database table: cat5_org
Select type: First maching record
Where conditions
org_id = {data:id}


pages/Actions/submit
new Save Data
Database table: cat5_org
Data provider: {Data3}



Case 1 - Update =======================================================================
http://www.conhecimentopublico.com.br/index.php?option=com_chronoforms6&chronoform=orgaos&id=112
====Debug Load========================================================================
Array
(
[option] => com_chronoforms6
[chronoform] => orgaos
[id] => 112
[rot] => http://www.conhecimentopublico.com.br/C5/tabelas/orgaos?ope=rev
[pes] => 648
[Itemid] =>
[event] => submit
[org_sigla] => MAPAaaab22
[org_nome] => Ministério da Agricultura, Pecuária e Abastecimento
[button3] =>
[org_id] => 112
)
Array
(
[read_data3] => Array
(
[log] => Array
(
[0] => SELECT `Data3`.`org_id` AS `Data3.org_id`, `Data3`.`org_sigla` AS `Data3.org_sigla`, `Data3`.`org_sigla_longa` AS `Data3.org_sigla_longa`, `Data3`.`org_nome` AS `Data3.org_nome`, `Data3`.`org_nome_ident` AS `Data3.org_nome_ident`, `Data3`.`org_pai_id` AS `Data3.org_pai_id`, `Data3`.`org_sup_id` AS `Data3.org_sup_id`, `Data3`.`org_nivel` AS `Data3.org_nivel`, `Data3`.`org_seq` AS `Data3.org_seq`, `Data3`.`org_seq_fim` AS `Data3.org_seq_fim` FROM `cat5_org` AS `Data3` WHERE `Data3`.`org_id` = '112' LIMIT 100;
)

[var] => Array
(
[Data3] => Array
(
[org_id] => 112
[org_sigla] => MAPAaaab
[org_sigla_longa] => MAPAzaz
[org_nome] => Ministério da Agricultura, Pecuária e Abastecimento
[org_nome_ident] => Ministério da Agricultura, Pecuária e Abastecimento
[org_pai_id] => 0
[org_sup_id] => 112
[org_nivel] => 1
[org_seq] => 8000
[org_seq_fim] => 15999
)

)

)

)

===================================================================================================
=== RESULT===================================
error
1062 Duplicate entry '112' for key 'PRIMARY'



Case 2 - Update =======================================================================
http://www.conhecimentopublico.com.br/index.php?option=com_chronoforms6&chronoform=orgaos&id=112
===Debug load=====================================================================
Array
(
[option] => com_chronoforms6
[chronoform] => orgaos
[id] => 0
[rot] => http://www.conhecimentopublico.com.br/C5/tabelas/orgaos?ope=rev
[pes] => 648
[Itemid] =>
)
Array
(
[read_data3] => Array
(
[log] => Array
(
[0] => SELECT `Data3`.`org_id` AS `Data3.org_id`, `Data3`.`org_sigla` AS `Data3.org_sigla`, `Data3`.`org_sigla_longa` AS `Data3.org_sigla_longa`, `Data3`.`org_nome` AS `Data3.org_nome`, `Data3`.`org_nome_ident` AS `Data3.org_nome_ident`, `Data3`.`org_pai_id` AS `Data3.org_pai_id`, `Data3`.`org_sup_id` AS `Data3.org_sup_id`, `Data3`.`org_nivel` AS `Data3.org_nivel`, `Data3`.`org_seq` AS `Data3.org_seq`, `Data3`.`org_seq_fim` AS `Data3.org_seq_fim` FROM `cat5_org` AS `Data3` WHERE `Data3`.`org_id` = '0' LIMIT 100;
)
[var] =>
)
)

===Debug submit=====================================================================

Array
(
[option] => com_chronoforms6
[chronoform] => orgaos
[id] => 0
[rot] => http://www.conhecimentopublico.com.br/C5/tabelas/orgaos?ope=rev
[pes] => 648
[event] => submit
[org_sigla] => aaa teste
[org_nome] => aaa teste
[button3] =>
[org_id] =>
[Itemid] =>
)
Array
(
[submit_validate_fields] => Array
(
[log] => Automatic validation enabled.
[var] => 1
)

[save_data4] => Array
(
[data] => Array
(
[created] => 2020-03-13 16:37:18
[user_id] => 648
[org_sigla] => aaa teste
[org_nome] => aaa teste
[org_id] =>
)

[_success] => Data saved successfully
[log] => Array
(
[0] => INSERT INTO `cat5_org` (`org_sigla`, `org_nome`, `org_id`) values ('aaa teste', 'aaa teste', '');
)

[var] => Array
(
[org_sigla] => aaa teste
[org_nome] => aaa teste
[org_id] => 241
)
)
)
This topic is locked and no more replies can be posted.