Forums

Two little hack for Server side validation form

meltz 25 Jul, 2008
For real, I have a hard time getting chronoform to work with server side validation. After a whole week of trial and error I finally figure it out to create a contact form that use server side server side validation.

I would like to share 2 little hacks, not sure is that consider hack anot. 🤣

1. If you want the form and error to display on the same page instead of going to a new page after submitting, go to
Form URLs > Submit URL key in "index.php?option=com_chronocontact&task=send&chronoformname=contactForm&Itemid=12".

The front part of the url can copy from chronoform front page under Link. Itemid=12 is the menu id where you want the submit page to go back to.


2. Stop the form to send out email if validation contain error. Solution can be found in some of the thread but I would like to share the simple method for server side validation.

In chronocontact.php after line 419 comment out the existing method, type in


if ( !empty($rows[0]->onsubmitcodeb4) ) 
{ 
   if ($returnval = eval( "?>".$rows[0]->onsubmitcodeb4 )) 
   {  
     showform($_POST);  // shown the form again if contain error
     return; 
   } 
} 


after the change in chronocontact.php file, at On Submit code - before sending email: type in


$errormessag = 'anything'; // fake info
return $errormessag; // return will prevent the email from sending out if there is any validating error


Hope is not too confusing, not very good at explaining stuff. :mrgreen:
GreyHead 25 Jul, 2008
Hi meltz,

I think that should all work - though I'm not sure about the Submit URL.

An easier solution is to use the ChronoForms showform($_POST); function to re-display the form together with the current values of $_POST - which you can validate, change and add to in the OnSubmit code.

To stop the email and save operations set $error_found = true;.

Bob
meltz 31 Jul, 2008
Thanks for yr advise =)
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger