Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS QUESTION FOR WEB APP REQUIRE KNOWLEDGE OF PHP AND JAVA SCRIPTING PHP QUESTION Q1a, Add booking reference field to the data entry form

THIS IS QUESTION FOR WEB APP REQUIRE KNOWLEDGE OF PHP AND JAVA SCRIPTING

PHP QUESTION

Q1a,

Add booking reference field to the data entry form

Modify data_form.php to provide a labelled text field to accept a string of 9 characters in the data entry form.

Mike wants to also capture the booking reference in the form.

Add a label with the text Booking Reference and a corresponding text input field, and feedback element to the data entry form. Note that the input field should have a size limit of 9 characters and must be completed with 9 characters by the user. Mike does not want to capture information other than from customers, so every entry will have a booking reference. When the limit is reached it should stop accepting characters, but no message should be produced. Your new form field should have a suitable and meaningful name attribute and use the same name as its id.

The field value should be empty when the page loads.

If you examine the supplied code carefully and observe how the current labels, fields and feedback are implemented, these will give you a good framework from which you can create the additional label, field and feedback element.

SOURCE OF CODE FOR data_form.php REQUIRE ADJUST:

// For security, required PHP files should "die" if SAFE_TO_RUN is not defined if (!defined('SAFE_TO_RUN')) { // Prevent direct execution - show a warning instead die(basename(__FILE__) . ' cannot be executed directly!'); } ?>

Executing:

Generating a HTML form to match the columns in the database table

" onchange="validate(event.target)" />

" onchange="validate(event.target)" />

" onchange="validate(event.target)" />

">cancel

Completed generating a HTML form to match the columns in the database table

Java scripting question

Q1b,

Modify admin.js to provide client-side validation of the Booking Reference field using JavaScript.

Mike wants the client-side to check for mistyped booking references and report them rather than submitting them to the server. He has decided that JavaScript client-side validation is needed to achieve that.

All booking references start with a group of three letters, followed by a hyphen and then a five-digit number.

You need to extend the existing JavaScript validation so that the booking reference field is constrained as described.

To do that, you will need to add additional code to the function validate() to recognise and check the new field, and modify the function validateForm() so the form cannot be submitted without a valid booking reference.

Add a comment to your validation code explaining the meaning of each part of your booking reference validation expression.

SOURCE CODE FOR admin.js REQUIRE TO CHANGE:

function validate(inputElement) { console.log("validate() called for inputElement:", inputElement);

if (!inputElement) { // This error may be caused by calling document.getElementById() // but there is no HTML element with the id attribute value you provide console.error("validate() called with no input element"); return false; }

var feedbackElement = document.getElementById("feedback_" + inputElement.id); if (!feedbackElement) { // This error may be caused by adding an input with e.g. id="boop" // but no matching feedback element with e.g. id="feedback_boop" console.error( "validate() called but there is no element to provide feedback for this input" ); return false; }

var pattern; // regular expression to match input against var feedback; // feedback about input if it is invalid

// TODO: Change these patterns/feedback according to the inputs you expect

if (inputElement.id == "firstname") { // ^$ = anchors, [a-zA-Z0-9 ] = letters/digits/spaces, * = 0 or more characters pattern = /^[a-zA-Z0-9 ]*$/; feedback = "Only letters, numbers and spaces are permitted"; }

if (inputElement.id == "lastname") { // ^$ = anchors, [a-zA-Z0-9 ] = letters/digits/spaces, * = 0 or more characters pattern = /^[a-zA-Z0-9 ]*$/; feedback = "Only letters, numbers and spaces are permitted"; }

if (inputElement.id == "email") { // ^$ = anchors, .+ = 1+ of any character, \@ = one @ symbol pattern = /^.+\@.+$/; feedback = "Only valid email addresses are permitted"; }

// Check that this is an input element we know how to validate if (!pattern) { // This error may be caused by adding an input with e.g. id="boop" // but no matching line above if (inputElement.id == "boop")... console.warn("validate() called but input id is not recognised"); return false; }

// Read the input value from the input element var value = inputElement.value; // Start by assuming the input is valid var valid = true;

// Test the input value against the regular expression pattern if (pattern.test(value)) { feedback = "Valid"; // Set the class attribute value of the feedback element to change its colour feedbackElement.className = "valid"; } else { // Set the class attribute value of the feedback element to change its colour feedbackElement.className = "invalid"; // The value is invalid valid = false; }

// Show the feedback message on the page feedbackElement.innerText = "Client feedback: " + feedback; if (value != "") { // If there is a value, show this too feedbackElement.innerText += ": " + value; }

return valid; }

function validateForm() { // Start by assuming the form is valid var valid = true;

// Validate each known input // TODO: Change these checks according to the inputs you expect valid = valid && validate(document.getElementById("firstname")); valid = valid && validate(document.getElementById("lastname")); valid = valid && validate(document.getElementById("email"));

// Feedback if form cannot be submitted if (!valid) { alert("Client message: Form data is invalid - please check and try again!"); }

return valid; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential Data Protection For Estate Agencies In Singapore 2024

Authors: Yang Yen Thaw Yt

1st Edition

B0CQK79WD3, 979-8872095392

More Books

Students also viewed these Databases questions

Question

a. How do you think these stereotypes developed?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago