Intercepting a Form Submission
	
	
		Hi,
Hoping someone can help a developer noob with a question --
Is it possible to intercept a form submission before it is processed, run a check on the fields submitted, and only complete submission if a certain custom condition is met?
The 'processFormData' hook appears to fire after the submission, so I can't use that.
I've also tried the 'validateFormField' hook, but I can't figure out how to use it -- i.e. how to access the properties in the Widget object that is passed through.
How would a seasoned developer handle this?
Thanks!
EDIT: 
Now I'm extending the Form Class, writing a custom processFormData() method that runs my checks before calling parent::processFormData(). That sounds like something someone who knows what are were doing would do... :)
	 
	
	
	
		Re: Intercepting a Form Submission
	
	
		which properties do you need?
you can get a list of available properties looking at the widget api
http://api.contao.org/__filesource/f....php.html#a212
if you want to "invalidate" the widget passed to the validateFormField hook just add an error to it using the addError method
http://api.contao.org/__filesource/f....php.html#a255
hope this helps in some way
	 
	
	
	
		Re: Intercepting a Form Submission
	
	
		Thanks again, Ga.N -- the API is definitely making more sense to me lately (before it just scared me).
I don't know what I was doing wrong before (and I scrapped the code), but when I used the 'validateFormField' hook, it seemed that no matter what I tried, I was unable get any property values from the Widget object that was passed through.
For instance '$objWidget -> strClass' would always give me a blank value, even if the Widget item actually had a class applied to it.
	 
	
	
	
		Re: Intercepting a Form Submission
	
	
		
	Quote:
	
		
		
			
				Originally Posted by Medianomaly
				
			
			Thanks again, Ga.N -- the API is definitely making more sense to me lately (before it just scared me).
I don't know what I was doing wrong before (and I scrapped the code), but when I used the 'validateFormField' hook, it seemed that no matter what I tried, I was unable get any property values from the Widget object that was passed through.
For instance '$objWidget -> strClass' would always give me a blank value, even if the Widget item actually had a class applied to it.
			
		
	 
 you can't retrieve the strClass property because it is "protected" but you can retrieve the 'class' property (as you can see looking at the __get method of the Widget class)
	 
	
	
	
		Re: Intercepting a Form Submission
	
	
		Ahh -- I completely see what you mean now, thanks!
	 
	
	
	
		Re: Intercepting a Form Submission
	
	
		The FormAuto module uses EVERY single form interception there is. Both loading and rendering form widgets (to add content to the label and prevent submission with errors) and also post-process the form using the HOOK. Look at the formauto/config/config.php file to see how many HOOKS you need to process the form.