Foren

custom field validation

thumbnail
sujay paul, geändert vor 11 Jahren.

custom field validation

Regular Member Beiträge: 164 Beitrittsdatum: 28.10.11 Neueste Beiträge
Hi,

I have add a custom field in liferay 6.1 create account screen .
the new field is "Phone Number"
But i can not add validation for this custom field such as the Phone number should start with 9 ,8 or 7 as well as the length should not more than 10 digit etc.
In future i will add more custom field with validation.
How can i do it?

I had create a hook for it & modify the create_account.jsp page & add this chunk of code to display it
<!-- add for phone -->
<liferay-ui:custom-attribute className="com.liferay.portal.model.User"
classPK="<%= 0l %>"
editable="<%= true %>"
label="<%= true %>"
name="Phone No"
/>


Please help.
thumbnail
Jitendra Rajput, geändert vor 11 Jahren.

RE: custom field validation

Liferay Master Beiträge: 875 Beitrittsdatum: 07.01.11 Neueste Beiträge
You need to override action class for create account . If i am not wrong then it is CreateAccountAction.java ..
Override class using hook and your problem should resolved.
Atul Patel, geändert vor 11 Jahren.

RE: custom field validation

New Member Beiträge: 18 Beitrittsdatum: 12.01.12 Neueste Beiträge
I recommend doing Jitendra's suggestion for a server side check and if you want to provide real-time error handling also, then do the input check client side with javascript.
thumbnail
Apoorva Prakash, geändert vor 11 Jahren.

RE: custom field validation

Liferay Master Beiträge: 658 Beitrittsdatum: 15.06.10 Neueste Beiträge
sujay paul:
Hi,

I have add a custom field in liferay 6.1 create account screen .
the new field is "Phone Number"
But i can not add validation for this custom field such as the Phone number should start with 9 ,8 or 7 as well as the length should not more than 10 digit etc.
In future i will add more custom field with validation.
How can i do it?

I had create a hook for it & modify the create_account.jsp page & add this chunk of code to display it
<!-- add for phone -->
<liferay-ui:custom-attribute className="com.liferay.portal.model.User"
classPK="<%= 0l %>"
editable="<%= true %>"
label="<%= true %>"
name="Phone No"
/>


Please help.


Try the following:
<aui:script use="liferay-form">
         Liferay.Form.register(
             {
                 id: '<portlet:namespace />fm',
                fieldRules: [
                     {
                         body: '',
                         custom: false,
                         errorMessage: 'Please enter the company name.',
                       fieldName: '<portlet:namespace />ExpandoAttributeName',
                        validatorName: 'required'
                    }
                ]
            }
        );
    </aui:script>

hope this will help...

Thanks and Regards,
Apoorva Prakash
thumbnail
sujay paul, geändert vor 11 Jahren.

RE: custom field validation

Regular Member Beiträge: 164 Beitrittsdatum: 28.10.11 Neueste Beiträge
Hi Apoorva ,
I had attached your code.
But its not working.

Here is my code.
Please tell me the error.
Thanks in advance.


<%--
/**
* Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@ include file="/html/portlet/login/init.jsp" %>

<%
String redirect = ParamUtil.getString(request, "redirect");

String openId = ParamUtil.getString(request, "openId");

PasswordPolicy passwordPolicy = PasswordPolicyLocalServiceUtil.getDefaultPasswordPolicy(company.getCompanyId());

Calendar birthday = CalendarFactoryUtil.getCalendar();

birthday.set(Calendar.MONTH, Calendar.JANUARY);
birthday.set(Calendar.DATE, 1);
birthday.set(Calendar.YEAR, 1990);

boolean male = ParamUtil.getBoolean(request, "male", true);
%>

<portlet:actionURL var="createAccoutURL">
<portlet:param name="saveLastPath" value="0" />
<portlet:param name="struts_action" value="/login/create_account" />
</portlet:actionURL>

<aui:form action="<%= createAccoutURL %>" method="post" name="fm">
<aui:input name="<%= Constants.CMD %>" type="hidden" value="<%= Constants.ADD %>" />
<aui:input name="redirect" type="hidden" value="<%= redirect %>" />
<aui:input name="openId" type="hidden" value="<%= openId %>" />

<liferay-ui:error exception="<%= AddressCityException.class %>" message="please-enter-a-valid-city" />
<liferay-ui:error exception="<%= AddressStreetException.class %>" message="please-enter-a-valid-street" />
<liferay-ui:error exception="<%= AddressZipException.class %>" message="please-enter-a-valid-postal-code" />
<liferay-ui:error exception="<%= CaptchaMaxChallengesException.class %>" message="maximum-number-of-captcha-attempts-exceeded" />
<liferay-ui:error exception="<%= CaptchaTextException.class %>" message="text-verification-failed" />
<liferay-ui:error exception="<%= CompanyMaxUsersException.class %>" message="unable-to-create-user-account-because-the-maximum-number-of-users-has-been-reached" />
<liferay-ui:error exception="<%= ContactFirstNameException.class %>" message="please-enter-a-valid-first-name" />
<liferay-ui:error exception="<%= ContactFullNameException.class %>" message="please-enter-a-valid-first-middle-and-last-name" />
<liferay-ui:error exception="<%= ContactLastNameException.class %>" message="please-enter-a-valid-last-name" />
<liferay-ui:error exception="<%= DuplicateUserEmailAddressException.class %>" message="the-email-address-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= DuplicateUserIdException.class %>" message="the-user-id-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= DuplicateUserScreenNameException.class %>" message="the-screen-name-you-requested-is-already-taken" />
<liferay-ui:error exception="<%= EmailAddressException.class %>" message="please-enter-a-valid-email-address" />
<liferay-ui:error exception="<%= NoSuchCountryException.class %>" message="please-select-a-country" />
<liferay-ui:error exception="<%= NoSuchListTypeException.class %>" message="please-select-a-type" />
<liferay-ui:error exception="<%= NoSuchRegionException.class %>" message="please-select-a-region" />
<liferay-ui:error exception="<%= PhoneNumberException.class %>" message="please-enter-a-valid-phone-number" />
<liferay-ui:error exception="<%= RequiredFieldException.class %>" message="please-fill-out-all-required-fields" />
<liferay-ui:error exception="<%= ReservedUserEmailAddressException.class %>" message="the-email-address-you-requested-is-reserved" />
<liferay-ui:error exception="<%= ReservedUserIdException.class %>" message="the-user-id-you-requested-is-reserved" />
<liferay-ui:error exception="<%= ReservedUserScreenNameException.class %>" message="the-screen-name-you-requested-is-reserved" />
<liferay-ui:error exception="<%= TermsOfUseException.class %>" message="you-must-agree-to-the-terms-of-use" />
<liferay-ui:error exception="<%= UserEmailAddressException.class %>" message="please-enter-a-valid-email-address" />
<liferay-ui:error exception="<%= UserIdException.class %>" message="please-enter-a-valid-user-id" />

<liferay-ui:error exception="<%= UserPasswordException.class %>">

<%
UserPasswordException upe = (UserPasswordException)errorException;
%>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_CONTAINS_TRIVIAL_WORDS %>">
<liferay-ui:message key="that-password-uses-common-words-please-enter-in-a-password-that-is-harder-to-guess-i-e-contains-a-mix-of-numbers-and-letters" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_INVALID %>">
<liferay-ui:message key="that-password-is-invalid-please-enter-in-a-different-password" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_LENGTH %>">
<%= LanguageUtil.format(pageContext, "that-password-is-too-short-or-too-long-please-make-sure-your-password-is-between-x-and-512-characters", String.valueOf(passwordPolicy.getMinLength()), false) %>
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORD_TOO_TRIVIAL %>">
<liferay-ui:message key="that-password-is-too-trivial" />
</c:if>

<c:if test="<%= upe.getType() == UserPasswordException.PASSWORDS_DO_NOT_MATCH %>">
<liferay-ui:message key="the-passwords-you-entered-do-not-match-each-other-please-re-enter-your-password" />
</c:if>
</liferay-ui:error>

<liferay-ui:error exception="<%= UserScreenNameException.class %>" message="please-enter-a-valid-screen-name" />
<liferay-ui:error exception="<%= WebsiteURLException.class %>" message="please-enter-a-valid-url" />

<c:if test='<%= SessionMessages.contains(request, "missingOpenIdUserInformation") %>'>
<div class="portlet-msg-info">
<liferay-ui:message key="you-have-successfully-authenticated-please-provide-the-following-required-information-to-access-the-portal" />
</div>
</c:if>

<aui:model-context model="<%= Contact.class %>" />

<aui:fieldset >

<table width="80%" align="center">
<tr>
<td width="33%">
<aui:input model="<%= User.class %>" name="firstName" />
</td>
<td width="33%">
<aui:input model="<%= User.class %>" name="middleName" />
</td>
<td width="33%">
<aui:input model="<%= User.class %>" name="lastName">
<c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_LAST_NAME_REQUIRED, PropsValues.USERS_LAST_NAME_REQUIRED) %>">
<aui:validator name="required" />
</c:if>
</aui:input>
</td>
</tr>
<tr>
<td width="33%">
<c:if test="<%= !PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_SCREEN_NAME_ALWAYS_AUTOGENERATE) %>">
<aui:input model="<%= User.class %>" name="screenName" />
</c:if>
</td>
<td width="33%">
<aui:input model="<%= User.class %>" name="emailAddress">
<c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.USERS_EMAIL_ADDRESS_REQUIRED, PropsValues.USERS_EMAIL_ADDRESS_REQUIRED) %>">
<aui:validator name="required" />
</c:if>
</aui:input>
</td>
<td width="33%">
<c:if test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_MALE) %>">
<aui:select label="gender" name="male">
<aui:option label="male" value="1" />
<aui:option label="female" selected="<%= !male %>" value="0" />
</aui:select>
</c:if>
</td>
</tr>
</table>
<table width="80%" align="center">
<tr>
<td width="33%">
<c:choose>
<c:when test="<%= PrefsPropsUtil.getBoolean(company.getCompanyId(), PropsKeys.FIELD_ENABLE_COM_LIFERAY_PORTAL_MODEL_CONTACT_BIRTHDAY) %>">
<aui:input name="birthday" value="<%= birthday %>" />
</c:when>
<c:otherwise>
<aui:input name="birthdayMonth" type="hidden" value="<%= Calendar.JANUARY %>" />
<aui:input name="birthdayDay" type="hidden" value="1" />
<aui:input name="birthdayYear" type="hidden" value="1970" />
</c:otherwise>
</c:choose>
</td>

<td width="33%" >
<!-- add for fon -->
<liferay-ui:custom-attribute
className="com.liferay.portal.model.User"
classPK="<%= 0l %>"
editable="<%= true %>"
label="<%= true %>"
name="Phone No"
/>

</td>
<td width="34%">
&nbsp;
</td>

</tr>
<tr>
<c:if test="<%= PropsValues.LOGIN_CREATE_ACCOUNT_ALLOW_CUSTOM_PASSWORD %>">
<td>
<aui:input label="password" name="password1" size="30" type="password" value="" />
</td>
<td>
<aui:input label="enter-again" name="password2" size="30" type="password" value="">
<aui:validator name="equalTo">
'#<portlet:namespace />password1'
</aui:validator>
</aui:input>
</td>
</c:if>
</tr>
</table>
<table width="80%" align="center">
<tr >
<td width="80%" align="left">
<c:if test="<%= PropsValues.CAPTCHA_CHECK_PORTAL_CREATE_ACCOUNT %>">
<portlet:actionURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>" var="captchaURL">
<portlet:param name="struts_action" value="/login/captcha" />
</portlet:actionURL>
<liferay-ui:captcha url="<%= captchaURL %>" />
</c:if>
</td>
</tr>
</table>
</aui:fieldset>
<table width="80%" align="ceter">
<tr>
<td width="80%">
<aui:button-row>
<aui:button type="submit" />
</aui:button-row>
</td>
</tr>
</table>

</aui:form>

<liferay-util:include page="/html/portlet/login/navigation.jsp" />

<c:if test="<%= windowState.equals(WindowState.MAXIMIZED) %>">
<aui:script>
Liferay.Util.focusFormField(document.<portlet:namespace />fm.<portlet:namespace />firstName);
</aui:script>
</c:if>

<aui:script use="liferay-form">
Liferay.Form.register(
{
id: '<portlet:namespace />fm',
fieldRules: [
{
body: '',
custom: false,
errorMessage: 'Please enter the company name.',
fieldName: '<portlet:namespace />Phone No',
validatorName: 'required'
}
]
}
);
</aui:script>
thumbnail
sujay paul, geändert vor 10 Jahren.

RE: custom field validation

Regular Member Beiträge: 164 Beitrittsdatum: 28.10.11 Neueste Beiträge
I think custom field can not validate.

Its a bug in liferay.

Hope it will fixe in future.
thumbnail
Achmed Tyrannus Albab, geändert vor 8 Jahren.

RE: custom field validation

Regular Member Beiträge: 158 Beitrittsdatum: 05.03.10 Neueste Beiträge
Sujay Kumar Paul:
I think custom field can not validate.

Its a bug in liferay.

Hope it will fixe in future.



Almost 3 year now. Basically i come from the future.
Did you find any solution to this abominable issue?