Presentation is loading. Please wait.

Presentation is loading. Please wait.

>> PHP: Form Processing

Similar presentations


Presentation on theme: ">> PHP: Form Processing"— Presentation transcript:

1 >> PHP: Form Processing

2 Processing File TRY NOW TRY NOW Will this work?
Create a new file called add-process.php Open the file and accept the submitted values from the form (using the $_POST variable) Write Insert Query to add the item to the database TRY NOW Will this work? Open the add-item.php file Go down to the form tag Add the attributes method action TRY NOW

3 Redirecting After a Form Submission
Approach 1: Within the process file Do as before Go to the add-process.php file Under the previous written code, create tags for new page Step 1: Create $title variable Step 2: Create $section variable Step 3: Include the header.php Step 4: Write the div tag with class “content” Step 5: Write a div tag with classes “section page” Step 6: Write a heading 1 tag with text “Add Item”. Step 7: Write a paragraph tag with text “Item Added to the Database Successfully” Step 8: Include the footer.php TRY NOW ISSUE Using back can resubmit the form again and send another

4 Redirecting After a Form Submission
Approach 2: Redirect to a new page Create a new file add-thanks.php Copy all the code from the previous add-process.php file we wrote to display the confirmation into this new page. TRY NOW For this to work, we need to add a redirect in the add-process.php Open the file add-process.php Add the following line at the end header(‘Location: add-thanks.php’); TRY NOW Method for the server and the browser to communicate before any HTML gets passed

5 Redirecting After a Form Submission
Approach 3: On the same add-item page Open the file add-item.php In the form tag Change the action attribute to “add-item.php” Open the file add-process.php and copy all the code to the beginning of the add-item.php file Modify the header command and change the page to add-item.php. Add a command exit; after the header function TRY NOW Avoids execution of other php code in the file Mind Exercise How can we display the confirmation message and remove the form within the same add-item.php file?

6 isset() PHP method Determines whether a certain variable has already been declared by PHP Returns a Boolean value true if the variable has already been set and false otherwise or if the variable is set to the value NULL Accepts an arbitrary amount of parameters Returns true if all the variables have been defined  otherwise, it returns false USAGE if(isset($_GET[“status”])) { }

7 Web-Based Systems - Misbhauddin
Selective Display Display this only when item is added to the database Display this only when the query failed Display this in the beginning HINT Use isset() function Use the header function with GET Declare a status variable Use it as conditional in the HTML Body Web-Based Systems - Misbhauddin

8 Summary Passing & Processing Form Variables
method=“GET” (Access using the $_GET Array) method=“POST” (Access using the $_POST Array) FORM Re-direction after Form Submission contact.php contact-process.php contact-thanks.php action=“contact-process.php” header(“Location: contact-thanks.php” action=“contact-process.php” Approach 1 action=“contact.php” Approach 2 Approach 3


Download ppt ">> PHP: Form Processing"

Similar presentations


Ads by Google