Forums

Form Wizard vs Easy Form Wizard: Server Side Validation

nxT 04 May, 2012
Hi,

I am trying to add server side validation but couldn't get it to work. In Form Wizard or Easy Form Wizard where to add the server side validation code?

In Easy Form Wizard I have added the following codes under "code" tab in "Custom Code - Before Email(s)" but nothing happening.


<?php
if ( isset($form->data['input_text_9']) AND $form->data['input_text_9'] != '' ) {
    $form->validation_errors[] = 'Do not fill this field';
    return false;
}
?>


The form still executing without any error. But If I echo the error message within the condition, it's printing the message.

I am confused where to add the validation code and which are the options need to enable to make it work.

Any help will be appreciated.

Thanks
GreyHead 04 May, 2012
Hi nxT,

In the Easy Form Wizard you could use the Custom Code before box but personally I'd switch to the Advanced Wizard.

In the Advanced Wizard drag a Custom Server Side Validation action from the Validation group into the On Submit event and move it up near to the top of the event. Drag an Event Loop action into the On Fail event. Click the spanner icon and add your validation code.

Bob
nxT 07 May, 2012
Bob,

Thanks a lot. The Advanced Wizard method you described working perfectly.

-nxT
iplanells 08 May, 2012
Hi,

I'm trying to do something similar. When the user submits, I need to check if some fields already exist on the table.

I put the following code into OnSubmit/Custom Server Side Validation:

<?php 
$input_dni=$form->data['input_text_ndocumento'];

$db =& JFactory::getDBO();
$query = "SELECT `ntarjeta`,`input_text_nombre`,`input_text_apellidos` FROM `lic70_chronoforms_data_SolicitudTarjetaRocasa` WHERE `input_text_ndocumento`='".$input_dni."'
";
$db->setQuery($query);
echo "select: ".$query.'</br>';
$results=$db->loadObjectList();
foreach($results as $result)
{
	echo "<pre>";
	print_r($result);
	echo "</pre>";
	echo "input_text_nombre: ".$form->data['input_text_nombre'].'<br/>';
	echo "input_text_apellidos: ".$form->data['input_text_apellidos'].'<br/>';
	if(($result->input_text_nombre==$form->data['input_text_nombre'])&&($result->input_text_apellidos==$form->data['input_text_apellidos']))
	{
		echo "Ya existe! Su nĂºmero de tarjeta es ".$result->ntarjeta;
		$form->data['ntarjeta']=$result->ntarjeta;	
	}else
	{
		echo "DNI ya dado de alta, nombre y apellidos no coinciden. Consulte a Rocasa";
		return false;
	}
}
?>


I get the correct answer (text before return false), but the form stills add a new entry to the table, and it shouldn't.
What am I doing wrong?

Thanks,
Isabel
Max_admin 09 May, 2012
Hi Isabel,

In order to stop the submission routine you have to make sure that:

#1- you have the "CSSV" action on the TOP of the submit event.
#2- you have an "Event loop" action in the "on fail" event of the "CSSV" action.
#3- your validation code return FALSE.

Do you meet all the requirements ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
iplanells 09 May, 2012
Hi,

I added "Event loop" action in the "on fail" event of the "CSSV" action, and now it works.
Yesterday, somehow I could not drop the event loop inside the on fail event :-( but today it works.

Thanks!

Isabel
FDigital01 14 May, 2012
i am also having problems dropping the event loop into the onfail area... it just won't go there...waiting to hear if anyone answers your question.
GreyHead 14 May, 2012
Hi,

Which browser are you using? I occasionally have problems but maybe one time in fifty or so. I find that dropping the action at the right hand end of the event usually works OK. Try going right until the horizontal scroll bar appears in the browser widow.

Bob
This topic is locked and no more replies can be posted.