Smarty html forms validation builtin request

From: Date: Mon, 31 Mar 2003 05:53:48 +0000
Subject: Smarty html forms validation builtin request
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1052@lists.php.net to get a copy of this message
Hi there, I was trying to change my Smarty.Compiler class to do some built in javascript routines to validate forms. The better I got was what I need to do to make it work correctly. Dear Monte Ohrt or Andrei Zmievski, Do you both like this idea? The thing is that the method compile file call the method compile_tag method. so then I've added a {form...} case in that method so it does interpret the tags {form name="x" method="..." ..} and either a closing case to "/form" tag that produces a simple </form> Here is the need, the compile tag only process smarty tags, leaving html code there. The need is to process first time the {form} {input} {select} tags finding a validate parameter equals to true like this {form name="test" validate="true"} Test {input type="text" name="testtext" size="10" validate="true" required="The field test is required."} {/form validate="true"} to change to <script language="javascript"> function validateForm(obj) { if(document.testtext.value == "") { alert{"The field test is required."); } } </script> <form name="test" onsubmit="validateForm(this);"> <input type="text" name="testtext" size="10"> </form> The main goal of this procedure is to read all the template searching for {form validate="true"} and change it to: <script language="javascript"> function validateForm(obj) { Then search for {input type="any" name="it" validate="true" required="Message"} and change it to: if(document.testtext.value == "") { alert{"Message"); } And then again search for {/form} and change it to: </script> With this we achieved the script validation and if it was assigned to the template like this : <html> <head> {scriptvalidate} </head> The code should be transformed to : <html> <head> <script language="javascript"> function validateForm(obj) { if(document.testtext.value == "") { alert{"The field test is required."); } } </script> </head> The main goal is to compile javascript validation first if exists then compile all tags like it does already only adding form /form input select and textarea cases on the _compile_tag method. And assign this javascript code to a smarty reserved variable that if defined in a part of each header template it assign it and change the code. With this we can add more functionality to smarty and to php either since it will be more complete. Then we can implement {input validate="true" required="yes" emailvalue="true"} routines to validate emails, integer numbers, etc. etc. etc. That's my 2 cents Ernani

« previous php.smarty.dev (#1052) next »