Saturday, 25 October 2014

Registration page with validation

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@page import="javax.portlet.PortletURL" %>
<%@page import="javax.portlet.ActionRequest" %>

<portlet:defineObjects />
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<link rel="stylesheet" href="css/layout-admin.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/jquery-ui.css" type="text/css" media="screen" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />

<%
  PortletURL regFormURL=renderResponse.createActionURL();
  regFormURL.setParameter(ActionRequest.ACTION_NAME,"regForm");
%>
<script>
function validateForm(){
var x=document.forms["regForm"]["username"].value;
if(x==null || x==""){
alert("Please Enter User Name");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["loginid"].value;
if(x==null || x==""){
alert("Please Enter login Id");
return false;
}
}

function validateForm(){
var x=document.forms["regForm"]["pwd"].value;
if(x==null || x==""){
alert("Please Enter password");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["confpwd"].value;
if(x==null || x==""){
alert("Please Retype password for confirm password");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["email"].value;
if(x==null || x==""){
alert("Please enter a valid Email id");
return false;
}
}

function validateForm() {
    var x = document.forms["regForm"]["email"].value;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
        alert("Not a valid e-mail address");
        return false;
    }
}
function validateForm(){
var x=document.forms["regForm"]["phone"].value;
if(x==null || x==""){
alert("Phone Number is mandatory Please enter your phone number");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["address"].value;
if(x==null || x==""){
alert("Please Enter your address");
return false;
}
}
function validateForm(){
var x=document.forms["regForm"]["answer"].value;
if(x==null || x==""){
alert("Please give answer for the selected question")
}
}



$(document).ready(function () {  
$("#datepicker1" ).datepicker( {
         changeDate:true,
changeMonth: true,//this option for allowing user to select month
         changeYear: true, //this option for allowing user to select from year range
         showOn: "button",
         buttonImage: "http://jqueryui.com/resources/demos/datepicker/images/calendar.gif",
         buttonImageOnly: true
       
}).datepicker("setDate", new Date());
   
});
</script>



<form name="<portlet:namespace/>regForm" method="POST" action="<%=regFormURL.toString()%>"  onsubmit="return validateForm()" >
<table summary="Demonstration form">
  <tbody>
  <tr>
    <td><label for="username">Enter your name:</label></td>
    <td><input name="<portlet:namespace/>username" size="35" maxlength="50" type="text"></td>
  </tr>
  <tr>
    <td><label for="dateOfBirth">Date Of Birth:</label></td>
    <td><input name="<portlet:namespace/>dateOfBirth" id="datepicker1" size="35" maxlength="50"        
                                      type="date"></td>
  </tr>
     
  <tr>
    <td><label for="email">Email Id:</label></td>
    <td><input name="<portlet:namespace/>email" size="35" maxlength="30" type="text"></td>
  </tr>
  <tr>
    <td><label for="pwd">Required password</label></td>
    <td><input name="<portlet:namespace/>pwd" size="35" maxlength="25" type="password"></td>
  </tr>
  <tr>
    <td><label for="confpwd">Confirm password</label></td>
    <td><input name="<portlet:namespace/>confpwd" size="35" maxlength="25" type="password"></td>
  </tr>  
 
  <tr>
    <td>
        <label for="address">Address:</label></td>
    <td><textarea name="<portlet:namespace/>address"  maxlength="50" ></textarea></td>
  </tr>
  <tr>
    <td><label for="country">Country:</label></td>
    <td><select name="<portlet:namespace/>country"> </select></td>
  </tr>
  <tr>
    <td><label for="state">State:</label></td>
    <td><select name="<portlet:namespace/>state"> </select></td>
  </tr>
  <tr>
    <td><label for="city">City:</label></td>
    <td><select name="<portlet:namespace/>city"> </select></td>
  </tr>  
  <tr>
    <td><label for="phone">Phone Number:</label></td>
    <td><input name="<portlet:namespace/>phone" size="35" maxlength="25" type="text"></td>
  </tr>  
 
 
   <tr>
    <td><label for="question">Security Question:</label></td>
    <td><select name="<portlet:namespace/>question" >
        <option value="000" selected="selected">Select any Security Question</option>
        <option value="008">What is your favourite Place</option>
        <option value="012">What is your pet name</option>
        <option value="016">What is your College Id</option>
        <option value="020">Who is your first Teacher</option>
        <option value="024">Your first school</option>
        <option value="660">Your bike number </option>
    </select>
    </td>
  </tr>
  <tr>
    <td><label for="answer">Security Answer:</label></td>
    <td><input name="<portlet:namespace/>answer" size="35" maxlength="50" type="text"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="Submit" value="Register" type="submit">
        <input name="Reset" value="Reset" type="reset">
       
       <!-- <button type="submit"><img src="/images/submit.png" alt="Submit"></button> -->
   
     </td>
   
   
  </tr>
  </tbody>
</table>
</form>

///action class

package com.register;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class RegisterPortlet extends MVCPortlet{

public void regForm(ActionRequest actionRequest,ActionResponse actionResponse)
       throws IOException, PortletException{
String username=ParamUtil.getString(actionRequest,"username");
    String dateOfBirth=ParamUtil.getString(actionRequest, "dateOfBirth");
    String email=ParamUtil.getString(actionRequest, "email");
    String pwd=ParamUtil.getString(actionRequest,"pwd");
    String confpwd=ParamUtil.getString(actionRequest, "confpwd");
    String address=ParamUtil.getString(actionRequest,"address");
    String country=ParamUtil.getString(actionRequest,"country");
    String state=ParamUtil.getString(actionRequest,"state");
    String city=ParamUtil.getString(actionRequest,"city");
    String phone=ParamUtil.getString(actionRequest,"phone");
    String question=ParamUtil.getString(actionRequest,"question");
    String answer=ParamUtil.getString(actionRequest,"answer");
   
    System.out.println("your in puts ::"+username+","+dateOfBirth+","
      +email+","+pwd+","+confpwd+","+address+","+country+","+state+","+city+","+phone+","+question+","+answer);

 
}
}

No comments: