AN
Limpar campo de formulário em caso de exceção
Fechado
Olá Pessoal! Bom, sou totalmente novato em PHP, utilizo o Adianti Studio Pro e preciso de ajuda. Criei a seguinte função com o objetivo de verificar se campo Nome já possui no banco de dados:
static function verificaDuplicidade ($nome){
try
{
TTransaction::open('sample'); // open a transaction
// get the form data into an active record cliente
$repository = new TRepository('cliente');
// load all objects
$collection = $repository->load(new TCriteria);
foreach ($collection as $object2)
{
if((strcmp($nome['NOME'], $object2->NOME))==0){
new TMessage('info', 'JÁ EXISTE UM CLIENTE CADASTRADO COM O MESMO NOME!');
// self::form::clear();
break;
}else{
}
}
TTransaction::close(); // close the transaction
}
catch (Exception $e) // in case of exception
{
new TMessage('error', 'Error ' . $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
E chamo a função:
$exit_action = new TAction(array($this, 'verificaDuplicidade'));
$NOME->setExitAction($exit_action);
A pergunta é: como posso limpar o campo nome se satisfazer o if da função?
Obrigado a todos!
static function verificaDuplicidade ($nome){
try
{
TTransaction::open('sample'); // open a transaction
// get the form data into an active record cliente
$repository = new TRepository('cliente');
// load all objects
$collection = $repository->load(new TCriteria);
foreach ($collection as $object2)
{
if((strcmp($nome['NOME'], $object2->NOME))==0){
new TMessage('info', 'JÁ EXISTE UM CLIENTE CADASTRADO COM O MESMO NOME!');
// self::form::clear();
break;
}else{
}
}
TTransaction::close(); // close the transaction
}
catch (Exception $e) // in case of exception
{
new TMessage('error', 'Error ' . $e->getMessage()); // shows the exception error message
$this->form->setData( $this->form->getData() ); // keep form data
TTransaction::rollback(); // undo all pending operations
}
}
E chamo a função:
$exit_action = new TAction(array($this, 'verificaDuplicidade'));
$NOME->setExitAction($exit_action);
A pergunta é: como posso limpar o campo nome se satisfazer o if da função?
Obrigado a todos!
Testa ai depois me diz.
Eae Felipe Cortez! Desculpe a demora, estava em viagem.
Cara, funcionou perfeitamente. Sem erros! Acabei de testar!
Muitíssimo Obrigado! Vlw!