Fórumok

Client Side Web Form Validation Help

Joshua Bertrand, módosítva 11 év-val korábban

Client Side Web Form Validation Help

New Member Bejegyzések: 17 Csatlakozás dátuma: 2012.05.01. Legújabb bejegyzések
My organization is using 6.1 EE with the "Web Form" portlet on several of our sites. We are needing to add validation scripts to our forms to ensure that a Phone Number holds numeric values and is at least 8 characters and that email address's must include @ symbol.

My attempts for the javascript code have not worked (although I am still in my early stages of learning javascript).... my question is.. are there any javascript examples out there that I can copy for this? I have been looking for the last hour and have been unsuccessful in finding anything that works.

Thank you for any help you can provide.
thumbnail
Vishal Panchal, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

Expert Bejegyzések: 289 Csatlakozás dátuma: 2012.05.20. Legújabb bejegyzések
Hi Joshua Bertrand,

Please take a look at this link

It will surely help you to learn basic validations using javascript as well as to get your desired..!!emoticon


Thanks & Regards,
Vishal R. Panchal
Joshua Bertrand, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

New Member Bejegyzések: 17 Csatlakozás dátuma: 2012.05.01. Legújabb bejegyzések
Thank you for the link. It was very helpful in understand the correct way to code a validation script. However, applying this to the Web Form portlet has still been unsuccessful and my form still submits when invalid characters are presented. Does anyone just have code that they use that you wouldn't mind providing?

Thank you.
thumbnail
Shinn Lok, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

Junior Member Bejegyzések: 89 Csatlakozás dátuma: 2011.01.14. Legújabb bejegyzések
Phone Number:
if(!/\D/.test(currentFieldValue) && currentFieldValue.length >= 8)
return true
else return false;

Email Address:
if (currentFieldValue.indexOf("@")>=0)
return true;
else return false;
thumbnail
Hitoshi Ozawa, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
if(!/\D/.test(currentFieldValue) && currentFieldValue.length >= 8)


Any reason to using (!/\D/ instead of /\d/ and just use .search instead of .test and just specifiy number of digits with [8] instead of using length?

if (currentFieldValue.indexOf("@")>=0)


This is a very primitive validation. Should use regular expression so it can be expanded to also test if the domain contains "." and if the left side and right side of "@" at least contain some character. There also may have been some restriction on the left side starting with a character. I think there was a validation check using regular expression in liferay already and it may just be a matter of copying it.
Joshua Bertrand, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

New Member Bejegyzések: 17 Csatlakozás dátuma: 2012.05.01. Legújabb bejegyzések
My form is still submitting with this code... here is a screen shot... is there anything I am doing wrong?
João Gomes, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

New Member Bejegyzések: 9 Csatlakozás dátuma: 2013.03.12. Legújabb bejegyzések
I have the exact same problem.
The validation script does not run.

How do i fix this, does it needs the script tags? Already tried and didnt work.
Help please.
thumbnail
Rajeev K, módosítva 10 év-val korábban

RE: Client Side Web Form Validation Help

Regular Member Bejegyzések: 214 Csatlakozás dátuma: 2009.06.19. Legújabb bejegyzések
João Gomes:
I have the exact same problem.
The validation script does not run.

How do i fix this, does it needs the script tags? Already tried and didnt work.
Help please.



Same problem.

The javascript code never gets called. Simple alert() is also not coming.

Whats could be the problem. Did you get it resolved?
thumbnail
Neetu Mishra, módosítva 10 év-val korábban

RE: Client Side Web Form Validation Help

Junior Member Bejegyzések: 75 Csatlakozás dátuma: 2012.05.21. Legújabb bejegyzések
Hi Joshua,

Below is the code for Email validation:

var isEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(currentFieldValue.search (isEmail) == -1 && currentFieldValue != '') {
return false;
} else {
return true;
}

Hope this will help you.emoticon

Regards,
Neetu
thumbnail
Vishal Panchal, módosítva 11 év-val korábban

RE: Client Side Web Form Validation Help

Expert Bejegyzések: 289 Csatlakozás dátuma: 2012.05.20. Legújabb bejegyzések
Joshua Bertrand:
Thank you for the link. It was very helpful in understand the correct way to code a validation script. However, applying this to the Web Form portlet has still been unsuccessful and my form still submits when invalid characters are presented. Does anyone just have code that they use that you wouldn't mind providing?

Thank you.


Hi Joshua Bertrand,

please find the file attached .
it is a sample code what u exactly want.

Please let me know if any inputs required..!!emoticon

Thanks & Regards,
Vishal R. Panchal
thumbnail
Rajeev K, módosítva 10 év-val korábban

RE: Client Side Web Form Validation Help

Regular Member Bejegyzések: 214 Csatlakozás dátuma: 2009.06.19. Legújabb bejegyzések
Vishal Panchal:
Joshua Bertrand:
Thank you for the link. It was very helpful in understand the correct way to code a validation script. However, applying this to the Web Form portlet has still been unsuccessful and my form still submits when invalid characters are presented. Does anyone just have code that they use that you wouldn't mind providing?

Thank you.


Hi Joshua Bertrand,

please find the file attached .
it is a sample code what u exactly want.

Please let me know if any inputs required..!!emoticon

Thanks & Regards,
Vishal R. Panchal



The Javascript function never gets called. What could be the problem?
thumbnail
Stefan Hüttenrauch, módosítva 9 év-val korábban

RE: Client Side Web Form Validation Help

New Member Bejegyzések: 5 Csatlakozás dátuma: 2011.04.06. Legújabb bejegyzések
Hi there,

let me point you to this link: http://stackoverflow.com/questions/11844221/liferay-webform-portlet-field-validation
...
Stop Tomcat
Go to APPLICATION_SERVER_ROOT_DIRECTORY/webapps/web-form-portlet/WEB-INF/classes directory
Open portlet.properties and change "validation.script.enabled" property from "false" to "true"
...

I would say: Download the source code and correct the portlet.properties file. Then deploy your own version of the web form portlet. I haven't found a switch in the portlet configuration to turn javascript validation on without modifying the properties file.

A hint in the configuration screen would have been nice ;-)

Regards
Stefan