Valdiation through Javascript - Popup "Fields required"

harzenmoser 01 Jan, 2009
I am now searching over 3 ours in this forum for a simple description of the following need: I have 4 fields in my form that are required to be filled. I would like to show a popup "Please enter required fields" when the user is pushing the submit button.
I am using Chronoforms 3.0 stable. It's really a creat tool :-)
GreyHead 01 Jan, 2009
Hi harzenmoser,

I'm sure that it's possible, but I haven't seen it done. The validation JavaScript supports custom messages, and I guess that they could be in pop-ups. You'll need to work out the coding though.

Bob
harzenmoser 01 Jan, 2009
Hi Bob
So i am a step nearer to the solution :-) Ich found a Code that compairs two fields (password validation) that works:

<?php
global $mainframe;
if(JRequest::getVar('text_3') != JRequest::getVar('text_4'))
return 'Sorry, your passwords do not match, try again!';
?>

So now instead of compairing the two fields i would like to check 4 fields if they are empty. I tried this:

<?php
global $mainframe;
if(JRequest::getVar('name') !== ''))
return 'Please fill in the required fields';
?>

But even more i shoud check 3 more fields :-)

Thanx for your help 🤣
GreyHead 01 Jan, 2009
Hi harzenmoser,

Why don't you just use the built in validation? The only thing it doesn't do is show the message in a pop-up. It doesn't do the password match eitehr but I posted a fix for that a few days ago.

Bob
harzenmoser 01 Jan, 2009
Hello again

We did some tests and we recognized that a lot of user don't see the message that is shoen automatically just under the required field. In the form we used before there was shown a popup after pushing the send button ("Please fill in the required fields"). This seemed to be userfriendlier than the solution used in chronoforms. So finally it's a customer decision / wish.

hugo
GreyHead 01 Jan, 2009
Hi harzenmoser,

So back to my earlier post - use the built in validation but customise the error message.

Bob
harzenmoser 01 Jan, 2009
So i used this code on the server side validation:
<?php
global $mainframe;
if(JRequest::getVar('name') !== ''))
return 'Please fill in the required fields';
?>
I got this error message (the form has been sent):

Parse error: syntax error, unexpected T_RETURN in /home/www/web308/html/cms/components/com_chronocontact/chronocontact.php(190) : eval()'d code on line 4


Thak your for your message. We will contact you as soon as possible.

I guess the !== '' in the code is wrong...
GreyHead 02 Jan, 2009
Hi harzenmoser,

Yes the operator is wrong and there's an extra ). I think the code should be:
<?php
global $mainframe;
if ( JRequest::getVar('name') == '' ) return 'Please fill in the required fields';
?>
or you make it a bit shorter in this case
<?php
global $mainframe;
if ( !JRequest::getVar('name') ) return 'Please fill in the required fields';
?>

Bob
harzenmoser 02 Jan, 2009
Thank you Bob - it works 😀

So there's is a last question: How can i change the background colour of the table that contains the message? It's pink - at that doesn't match the template 8)

Hugo
GreyHead 02 Jan, 2009
Hi harzenmoser,

Just add a little css - I forget the class name that's applied - something like 'validation-advice'. Check the page source code to see exactly what it is.

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