Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Formcat suggestion

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
vego
Smarty Rookie


Joined: 24 Feb 2005
Posts: 23

PostPosted: Fri Mar 04, 2005 11:35 pm    Post subject: Formcat suggestion Reply with quote

- might apply to SmartyValidate as well.

It would be great to be able to define validation criteria as 'strict' or more 'relaxed' - to be able to define criteria that generated a warning, but still let the user submit the form (presents a yes/no dialog perhaps)

For my project, I need to generate warnings to alert the user that something is missing or incorrect with the form, but the user can submit it if s/he so wishes.

By glancing at the source code, I wonder if it could be accomplished by just changing the javascript alert()s to confim() boxes in the various validation criteria plugins?
Back to top
View user's profile Send private message
vego
Smarty Rookie


Joined: 24 Feb 2005
Posts: 23

PostPosted: Sun Mar 06, 2005 10:48 pm    Post subject: Reply with quote

For those who might be interested, here's some changes to the code I did which seemed to do the trick. Example from validators/js_validator_notEmpty.php:

change
Code:

        if(!empty($field)){
           $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nalert('$message');\n".
                   $focusStr."return false;\n}\n";
           return $str;
        }


to
Code:

        if(!empty($field)){
           if ($optional) {
            $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nif(!confirm('$message - submit anyway?')) {".
                  $focusStr."return false;}\n}\n";
         } else {
            $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nalert('$message');\n".
                  $focusStr."return false;\n}\n";
         }
           return $str;
        }

and add optional=1 to the validation code in the template, eg:
{formcat check="notEmpty" field="FullName" message="Name missing" optional=1}
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Mar 07, 2005 3:39 pm    Post subject: Reply with quote

With SmartyValidate (since there is no client side javascript), you could add a checkbox to the form that confirms that they really do want to leave the field empty. You could then test for this in your validator. This is something that could be on the form along side the field, or show up along with the error message upon a form redraw.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Mar 07, 2005 3:45 pm    Post subject: Reply with quote

btw, the javascript code:

if(!confirm('foo')) return false;

is redundant, it can be shortened to:

return(confirm('foo'));
Back to top
View user's profile Send private message Visit poster's website
vego
Smarty Rookie


Joined: 24 Feb 2005
Posts: 23

PostPosted: Mon Mar 07, 2005 4:16 pm    Post subject: Reply with quote

mohrt wrote:
btw, the javascript code:

if(!confirm('foo')) return false;

is redundant, it can be shortened to:

return(confirm('foo'));


Are you sure? Because in the event confirm returns false (we don't want to submit) we want to BOTH return false and execute $focusStr (focus on field).

I do admit I've only skimmed through the code and made some changes that seem to work Question Wink
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Mar 07, 2005 4:24 pm    Post subject: Reply with quote

You can still test for that:

return(fc['$field'].value=='' && confirm('foo'));

either way works, but the former is somewhat confusing until you stare at it Wink
Back to top
View user's profile Send private message Visit poster's website
vego
Smarty Rookie


Joined: 24 Feb 2005
Posts: 23

PostPosted: Mon Mar 07, 2005 6:44 pm    Post subject: Reply with quote

mohrt wrote:
With SmartyValidate (since there is no client side javascript), you could add a checkbox to the form that confirms that they really do want to leave the field empty. You could then test for this in your validator. This is something that could be on the form along side the field, or show up along with the error message upon a form redraw.


In my project, I have so many fields that would require a checkbox that I think it is not practical. But it might perhaps be possible to add a single checkbox (possibly only visible on redraw after validation failure), and then check for this *before* validation on subsequent submit:

(modified from http://www.phpinsider.com/php/code/SmartyValidate/)
[php:1:0e7c6591c1]
if(($_POST['submit_with_errors']=='y') || SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
$smarty->display('success.tpl');
} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->assign('display_checkbox', true);
$smarty->display('form.tpl');
[/php:1:0e7c6591c1]

template:
Code:

<form>
...
{if $display_checkbox}
Submit with errors: <input type="checkbox" value="y">
{/if}
</form>


...on the other hand, this would not let me distinguish between 'strict' and 'nonstrict' validation. Perhaps a parameter could be passed to smartyvalidate?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Mar 07, 2005 7:11 pm    Post subject: Reply with quote

All parameters passed through the {validate} function are available to the validator, so you could pass a strict flag and test for it.
Back to top
View user's profile Send private message Visit poster's website
joey
Smarty Regular


Joined: 29 Oct 2003
Posts: 57

PostPosted: Sat Apr 30, 2005 4:16 pm    Post subject: Reply with quote

vego wrote:
For those who might be interested, here's some changes to the code I did which seemed to do the trick. Example from validators/js_validator_notEmpty.php:

change
Code:

        if(!empty($field)){
           $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nalert('$message');\n".
                   $focusStr."return false;\n}\n";
           return $str;
        }


to
Code:

        if(!empty($field)){
           if ($optional) {
            $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nif(!confirm('$message - submit anyway?')) {".
                  $focusStr."return false;}\n}\n";
         } else {
            $str = "\n\n// checks if ".$field." has been filled\n\n".
                  "if(fc['$field'].value==''){\nalert('$message');\n".
                  $focusStr."return false;\n}\n";
         }
           return $str;
        }

and add optional=1 to the validation code in the template, eg:
{formcat check="notEmpty" field="FullName" message="Name missing" optional=1}



Thanks for your sugestions.
It's possible for me to add them into new version.
_________________
Joey
Senior Developer & Designer
-------------------------------------------
http://www.propagator.net
[SourceForge Project] Formcat with Smarty!
http://www.propagator.net/formcat/
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP