Send an email if when the record is updated and a checkbox field is active

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Send an email if when the record is updated and a checkbox field is active

Post by fgazza » 2020-08-04 09:48

Hi everyone.
I can't solve this problem:
I have a "richiesta_attestato" table with a checkbox field "invia_comunicazione".
I would like that if a record is updated and the checkbox field "invia_comunicazione" is selected (ie active, ie the value is "1") an email will be sent to recipients set in my code.
If, on the other hand, when the record is updated, the checkbox field "invia_comunicazione" is not active, no mail must be sent.

I tried this code (in after update function) but it doesn't work !!!

Code: Select all

	
		$invio_comunicazione =sqlValue("SELECT invia_comunicazione FROM richiesta_attestato where rich_att_ID='{$selectedID}'"
		);
		
		if($invio_comunicazione =1){
		
		// i try also with if($invio_comunicazione =1){ as i explain at the end of the code //
		
		@mail(
		// mail recipient
		// da aggiungere per recuperare in automatico l'indirizzo e-mail inserito nel campo e_mail_per_info,
		"[email protected], {$data['recapito_email']}",
		
		// subject
		"Sulla Buona Strada - La tua richiesta di attestato per l'attività è stata aggiornata: $titolo_evento. [Partecipante: {$data['nome']} {$data['cognome']}] ",
		
		// message
		"Abbiamo aggiornato la tua richiesta di attestato per l'attività: $titolo_evento.\n\n".
		
		"Evento: $titolo_evento\n".
		"Data: $data_evento\n".
		"Luogo: $dove_evento\n".
		"Orario: dalle $orario_inizio_evento alle $orario_fine_evento\n".
		"$eventuali_altre_date_luoghi_orari\n\n".
		"PARTECIPANTE\n".
		"Nome: {$data['nome']}\n".
		"Cognome: {$data['cognome']}\n\n".
		"Ente: $ente_appartenenza_partecipante {$data['ente_di_appartenenza']}\n\n".
		"E-mail: {$data['recapito_email']}\n".
		"Telefono: {$data['recapiti_telefonici']}\n\n\n".
		"Di seguito le informazioni sullo stato della tua richiesta:\n".
		"{$data['stato_richiesta']}\n\n\n".
		// sender address
		"From: [email protected]"
		
	);

	}
In particular:
- If I set the query with == 1 no email starts under any circumstances (neither with active checkbox nor with inactive checkbox)
- If I set the query with = 1 the email starts in any case (both with active checkbox and with inactive checkbox)

Can anyone help me understand where I'm wrong?

THANK YOU!

Fabiano

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Send an email if when the record is updated and a checkbox field is active

Post by pbottcher » 2020-08-04 15:13

Hi,

what datatype is your invia_comunicazione field?

Can you try:

Code: Select all

sqlValue("SELECT invia_comunicazione FROM richiesta_attestato where rich_att_ID='$data['selectedID']'");

if($invio_comunicazione ==1){
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: Send an email if when the record is updated and a checkbox field is active

Post by fgazza » 2020-08-04 18:34

Thank you so much!
I solved the problem with your help and a little change to your code:

I put:

Code: Select all

$invio_comunicazione =sqlValue("SELECT invia_comunicazione FROM richiesta_attestato where rich_att_ID='{$data['selectedID']}'");
		
		if($invio_comunicazione ==1){
Now all works!

Thank you!

Fabiano

Post Reply