Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joshua Bertrand
Client Side Web Form Validation Help
August 24, 2012 9:52 AM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

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.
Vishal Panchal
RE: Client Side Web Form Validation Help
August 24, 2012 11:22 AM
Answer

Vishal Panchal

Rank: Expert

Posts: 280

Join Date: May 20, 2012

Recent Posts

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
RE: Client Side Web Form Validation Help
August 24, 2012 1:27 PM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

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.
Shinn Lok
RE: Client Side Web Form Validation Help
August 24, 2012 2:43 PM
Answer

Shinn Lok

LIFERAY STAFF

Rank: Junior Member

Posts: 89

Join Date: January 14, 2011

Recent Posts

Phone Number:
1if(!/\D/.test(currentFieldValue) && currentFieldValue.length >= 8)
2return true
3else return false;

Email Address:
1if (currentFieldValue.indexOf("@")>=0)
2return true;
3else return false;
Hitoshi Ozawa
RE: Client Side Web Form Validation Help
August 24, 2012 6:55 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

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.
Vishal Panchal
RE: Client Side Web Form Validation Help
August 25, 2012 12:05 AM
Answer

Vishal Panchal

Rank: Expert

Posts: 280

Join Date: May 20, 2012

Recent Posts

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
Attachments: ClientSideJSValidation.html (1.0k)
Joshua Bertrand
RE: Client Side Web Form Validation Help
August 30, 2012 11:58 AM
Answer

Joshua Bertrand

Rank: New Member

Posts: 17

Join Date: May 1, 2012

Recent Posts

My form is still submitting with this code... here is a screen shot... is there anything I am doing wrong?
Attachment

Attachments: Screen Shot 2012-08-30 at 1.28.29 PM.png (38.6k)
João Gomes
RE: Client Side Web Form Validation Help
March 25, 2013 3:41 AM
Answer

João Gomes

Rank: New Member

Posts: 9

Join Date: March 12, 2013

Recent Posts

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.
Neetu Mishra
RE: Client Side Web Form Validation Help
August 23, 2013 7:29 AM
Answer

Neetu Mishra

Rank: Junior Member

Posts: 76

Join Date: May 21, 2012

Recent Posts

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
Rajeev K
RE: Client Side Web Form Validation Help
January 5, 2014 10:20 PM
Answer

Rajeev K

Rank: Regular Member

Posts: 214

Join Date: June 18, 2009

Recent Posts

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?
Rajeev K
RE: Client Side Web Form Validation Help
January 5, 2014 10:21 PM
Answer

Rajeev K

Rank: Regular Member

Posts: 214

Join Date: June 18, 2009

Recent Posts

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?
Stefan Hüttenrauch
RE: Client Side Web Form Validation Help
July 14, 2014 2:54 AM
Answer

Stefan Hüttenrauch

Rank: New Member

Posts: 5

Join Date: April 6, 2011

Recent Posts

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