0

I am not able to post the new article on the website thats why i am directly contacting you if you can able to help me out with the following problems.

I am student. I have a very simple assignment and I did do the assignment but the requirement is not to use the PHP code in my HTML file.I used some PHP code HTML file in order to display error message.
Is there anyway if someone can help me with this?

I dont want to use PHP code in the html file.
Following are the requirements I need to follow in order to complete the problem!!!

Thanks in advance!!!

req:

Create HTML document and Name it “assignment2.html”
Make use of HTML5 doctype to your html document i.e. <! DOCTYPE html>
Add a form to the HTML document.
a. Make use of the method and action <form> attributes
i. The form must be submitted via the POST method
b. The form must contain the following fields:
i. Categories
1.<select> / drop down list
a.Add “categoryID” name to <select>
b.Add the following book categories as options:
i. Arts & Photography
Add option value “1”
ii. Children’s Books
Add option value “2”
iii.Computers & Technology
Add option value “3”
iv. Science & Math
Add option value “4”
ii. Book Title
1.[input type text]
iii.Author
1.[input type text]
iv.Description
1.[textarea]
v. ISBN
1.[input type text]
vi.Submit button [input type submit]
Create PHP document
a.Name it “process.php”
b.Make use of “if / else” statement to determine if submitted form values for “Book Title” and “ISBN” exist and are NOT empty
i. Make use of isset() function
ii.Make use of empty() function
iii.“echo” an appropriate error message when desired condition is not met.
c. Collect the submitted form values using the built-in $_POST array
i. Place collected values into local variables
ii.“echo” variable contents
Is anyone can help me with this?
I will post the code too.
HTML CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Assignment 2</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">

     <form action="process.php" method="post">
        <div id="data">
           <label>Categories:</label>
           <select name="categoryID">
             <option value="1">Arts & Photography</option>
             <option value="2">Children’s Books</option>
             <option value="3">Computers & Technology</option>
             <option value="4">Science & Math</option>
           </select>
           <br />
           <label>Book Title:</label>
           <input type="text" name="book_title" />
           <br />
           <label>Author:</label>
           <input type="text" name="author" />
           <br />
           <label>Description:</label>
           <textarea  name ="description" rows="3" ></textarea> 
           <br />
           <label>ISBN:</label>
           <input type="text" name="isbn" />
           <br />
        </div>
        <div id="buttons">
           <label>&nbsp;</label>
           <input type="submit" value="SUBMIT" name = "submit"/>
        <div/>
  </form>
<div/>
</body>
</html>

PHP CODE

<?php
//get the data from the form
$categoryID = $_POST['categoryID'];
$book_title = $_POST['book_title'];
$author = $_POST['author'];
$description = $_POST['description'];
$isbn = $_POST['isbn'];
//Validating the Book Title input vale
if ( empty($book_title) ) {
        $error_message = 'Book Title is a required field.'; 
    } else if ( is_numeric($book_title) )  {
        $error_message = 'Book Title must be a valid Charachter.'; 
    // validating ISBN Input Value
    } else if ( empty($isbn) ) {
        $error_message = 'ISBN is a required field.'; 
    } else if ( !is_numeric($isbn) )  {
        $error_message = 'ISBN must be a valid number.'; 
    } else if ( $isbn<= 0 ) {
        $error_message = 'ISBN must be greater than zero.';        
    // If all the data is correct then set the error_message to empty string
    } else {
        $error_message = '';
    }
    // if an error message exists, go to the Assignment2.html page
 if ($error_message != '') {
        include('Assignment2.html');
        exit();
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Assignment 2</title>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body>
<div id="content">
<label>Categories:</label>
<span><?php echo $categoryID; ?></span><br />
<label>Book Title:</label>
<span><?php echo $book_title; ?></span><br />
<label>Author:</label>
<span><?php echo $author; ?></span><br />
<label>Description:</label>
<span><?php echo $description; ?></span><br />        
<label>ISBN:</label>
<span><?php echo $isbn; ?></span><br />  
</div>
</body>
</html> 

Edited by diafol: apply code tags properly

3
Contributors
2
Replies
7
Views
5 Years
Discussion Span
Last Post by broj1
0

I think that exercise 2 shall be done with an external javascript file, otherwise you'll need to do another php file only to the alerts. But an .js file would be useful because remember that php executes in server.

0

I think you do not need any php nor javascript code in the html document according to the instructions. If required fields
are missing, you will handle an error message in the process.php.

In the process.php file first check whether the required fields are there (use isset() and empty() functions as it is said in the instructions):

if(isset['book_title'] && !empty['book_title'] && isset['isbn'] && !empty['isbn'] {
    // process the data or do whatever you want here
    // ...
// if required fields are not present, then do whatever you want to handle the error
} else {
    // display error message, provide a link to get back to the form etc
}

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.