Field form Information needed for HTML / Javascript form #include <stdio.h> #def
ID: 3598311 • Letter: F
Question
Field form Information needed for HTML / Javascript form
#include <stdio.h>
#define SIZE 5
struct date {
int month;
int day;
int year;
};
struct name {
char firstname[50];
char lastname[50];
char middlename[50];
};
struct height {
int feets;
int inches;
};
struct license {
char id[25]; // id
struct name n; // name struct which contains first name, last name, middle name
struct height h; // height struct which records both feets and inches
struct date dob; // date struct for date of birth
struct date expires; // date struct for expire date
struct date issued; // date struct for issued date
char sex; // char for sex 'M' or 'F'
char class_type; // license type. for example 'C'
char eyes_type[10]; // eye_color. for example "Blue"
};
int main() {
struct license drivers[SIZE]; // declaring license array
return 0;
}
Question 2 - HTML Take the information you modeled in question 1 and create an HTML form that has all the field information needed to submit to the registry to process your driver's license. Reference and start with the HTML template provided. Make your form easy to work with so it could be used in the future as an entry form to add information about driver's licenses. Question 3 - JavaScript In Question 2, you created an HTML form. Add JavaScript code to provide validation to those form fields you feel would benefit from having error checking. The template referenced in question 2 provides a few examples on how this is done, just expand upon it. It will contain a button that can be clicked to start the JavaScript form validation process.
<html>
<head>
<title> - License Form and Validator</title>
<script type="text/javascript">
//
// Template: License Form Validator
//
// Initialize any global variables to use in processing form data
//-----------------------------------------------------------------------------
//
// Name: validateLicense
//
// Description - This is the main entry point that is intially called
// when the user hits the "calculate" button in the
// HTML form. It will make various calls to functions and
// built-in functions to verify the fields that need to
// be validated (checked for any errors).
//
// Alert buttons are used to indicate issues with the
// form field values, and a final alert is used to indicate
// that the license form is validated and correct. The
// final alert will only display if no validation issues are
// found.
//
// In the real world you could then be confident to do
// something with your form data, such as write information
// to a file or send it to a program (e.g., Perl, Java, Ruby)
// on a web server that would connect to a database and insert
// the valid field information.
//
// Parameters: None
//
// Returns: 0 - successfully passed all validation
//
//----------------------------------------------------------------------------
function validateLicense() {
//
// Check all mandatory form fields to make sure they are not empty.
// If the field is empty then return (exit) from the function to put up an alert
//
// 1) Create variables to capture the values for all form field you are using
var licenseNumber = document.myLicense.licenseNumber.value;
// add other variables as needed for fields you want to check
// 2) Check that all mandatory fields have values
// If the License Number field is empty then exit the function.
if (fieldEmpty ("License Number", licenseNumber) ) { return; }
// Add other mandatory fields checks here using the fieldEmpty function
// 3) As needed, start validating fields if they have values that need to be verified
// Is License Number Alphanumberic (only contains letters and numbers)?
// NOTE: use the fieldAlphanumberic function and alert if needed
if ( fieldAlphanumeric ( "License Number", licenseNumber ) ) { return; }
// Validate values in other fields as needed ... use built in functions like isNaN and
// others as needed
// 4) S U C C E S S
//
// if everything works and it gets this far, all validations have passed, just present an alert message
alert ("License Information is Valid");
return 0; /* success */
}
//-----------------------------------------------------------------------------
//
// Name: fieldAlphanumeric
//
// Description - Checks to see if a field value is only AlphaNumeric, only
// letters (A-Z and a-z) and digits (0-9) are allowed).
//
// Sample Valid Values - 12A, abc12, and 9a1b12c
//
// Sample Invalid Value - 83$A% (has a $ and % character)
//
// Parameters: fieldName - The Field Name Label on the HTML form
// fieldValue - The actual value within the field being tested
//
// Returns: 1 - fieldValue contains non alphanumeric characters
// 0 - fieldValue contains alphanumeric characters
//
//----------------------------------------------------------------------------
function fieldAlphanumeric (fieldName, fieldValue)
{
var msg =" must contain only letters and numbers";
// these is a regular expression test (we'll cover this soon)
if ( /[^A-Za-z0-9]/.test(fieldValue) ) {
alert (fieldName + (msg));
return 1; // fails, contains non alphanumberic characters
}
else {
return 0; // passes, contains only alphanumeric characters
}
}
//-----------------------------------------------------------------------------
//
// Name: fieldEmpty
//
// Description - Determines if a given fieldValue is empty
//
// Parameters: fieldName - The Field Name Label on the HTML form
// fieldValue - The actual value within the field being tested
//
// Returns: 1 - fieldValue is empty
// 0 - fieldValue
//
//----------------------------------------------------------------------------
function fieldEmpty (fieldName, fieldValue) {
var msg=" is a required field";
if(fieldValue == "") {
alert (fieldName +(msg));
return 1;
}
else {
return 0;
}
}
// add other functions if you wish, but not mandatory or expected
</script>
</head>
<body>
<h1>myLicense Form Validator</h1>
<!--This is a comment. Comments are not displayed in the browser-->
<!-- Here is a simple form to get you started ... add the fields you -->
<!-- need to the form so it has all the license information that the -->
<!-- the mass registry would need to process and validate your license information -->
<form name="myLicense">
<table>
<tr>
<td>License Number:</td>
<td><input type="text" name="licenseNumber" /></td>
<!--Add other fields as needed, and maybe add other field attibutes ... like size -->
</tr>
<td>Another Field:</td>
<td><input type="text" name="otherField" /></td>
<!--Revise field information above with a real field and add other fields as needed -->
<tr>
<td> </td>
<td><input type="button" value="Validate" /> <input type="button" value="CE" /></td>
</tr>
<tr>
</table>
</form>
</body>
</html>
Explanation / Answer
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Registration Form</title>
</head>
<body>
<h1>Student Registration form</h1>
<form action="add.spring" method="post">
<table>
<tr>
<td>First Name</td>
<td><input type="text" name="id"></td>
<td>Last Name</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Middle Name</td>
<td><input type="text" name="password"></td>
<td>license</td>
<td><input type="text" name="confirmPassword"></td>
</tr>
<tr>
<td>State </td>
<td><input type="text" name="stateName"></td>
<td>City </td>
<td><input type="text" name="city"></td>
</tr>
<tr>
<td>Pin Code </td>
<td><input type="text" name="pinCode"></td>
<td>Mobile no. </td>
<td><input type="text" name="mobileNumber"></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
package com.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity(name="student")
public class License {
@Id
private int id;
private String fname;
private String lname;
private String Mname;
private String license;
private String city;
private String pinCode;
private String mobileNumber;
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getMname() {
return Mname;
}
public void setMname(String mname) {
Mname = mname;
}
public String getLicense() {
return license;
}
public void setLicense(String license) {
this.license = license;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPinCode() {
return pinCode;
}
public void setPinCode(String pinCode) {
this.pinCode = pinCode;
}
public String getMobileNumber() {
return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}
}
package com.dao;
import com.model.Licene;
public interface LicenseDAO {
public void createLicense(Person p);
}
package com.service;
import com.model.Person;
public interface LicenseService {
public void createLicense(Person p);
}
package com.service;
import org.springframework.transaction.annotation.Transactional;
import com.dao.PersonDAO;
import com.model.Person;
public class LicenseServiceImpl implements LicenseService {
private LicenseDAO LicenseDAO;
public void setLicenseDAO(LicenseDAO LicenseDAO) {
this.personDAO = personDAO;
}
package com.dao;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.collections.list.SynchronizedList;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import com.model.License;
public class LicenseDAOImpl implements LicenseDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sf) {
System.out.println("[......... sessionFactory initialized ......] ");
this.sessionFactory = sf;
}
public void addLicense(License p) {
Session session = this.sessionFactory.getCurrentSession();
session.save(p);
System.out.println("License saved successfully, License Details=" + p);
}
}
@Transactional
public void addPerson(Person p) {
this.personDAO.addPerson(p);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.