DB unique constraint

paolodefalco 29 Nov, 2011
Hi,
on the site of my school i've a form that saves data into a db table (the table has a unique constraint on 3 field CodClasse+CodMateria+A_S).
I need this functionality: after the data are send, mysql should control the uniquue constraint and, eventually, return an error message. How can i do?

Regards, Paolo
GreyHead 29 Nov, 2011
Hi Paolo,

I'm not sure - probably you need to hand-code the MySQL query and handle any MySQL errors returned.

Bob
paolodefalco 29 Nov, 2011
Hi Bob,
yes i suppose..can you help me?

Best regards, Paolo
Max_admin 01 Dec, 2011
I will work on the "CodClasse" as an example.

I will suppose the DB field is named "CodClasse" and the value from the form is under "CodClasse_field"

Use a "DB Record loader" action and enter "CodClasse" in the "DB field" and enter "CodClasse_field" in the "Request Param" and select the db table, then save, in the "On Found" event add a "Custom code" action and enter this code:


<?php
$form->validation_errors[] = "CodClasse is not unique because it has been found!";
?>


Then add an "Event loop" action after the "Custom code" one.

Save the form, done!

You may need to have 3 "Record loader" actions for the 3 DB fields..


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.