0% found this document useful (0 votes)
23 views

Working With Forms

Uploaded by

jaindisha731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Working With Forms

Uploaded by

jaindisha731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

WORKING WITH FORMS:

We mainly use HTML forms when collecting user input


in web-based applications. They range from contact
forms, login forms, and also registration forms. Forms
are the fundamental interface between the user and the
server. Creating a form on a web application is achieved
using HTML. PHP connects the web application with the
database server.

Through this article, you will learn how to:

 Create an HTML form.


 Learn about Hypertext Transfer Protocol (HTTP) request
methods (GET, POST, and PUT).
 Understand PHP POST and GET methods.

Overview of forms
A form is a document with blank fields for a user to insert or
update data. The user’s data is stored in the database and
retrieved anytime.

Using forms to collect data in a web application is a simple


task.

Some of the popular forms include:

 Contact Forms
 Search Forms
 Login Forms
 Registration Forms

The form is presented to the user who inserts data and


submits the form using a submit button. Most of the time, the
form data is sent to the server for processing. Processing
user input involves validating inputs, database operations,
and providing feedback to the user. There are four database
operations involved, these being create, read, update, and
delete.

Hypertext Transfer Protocol (HTTP) enables communication


between the client (browser) and the server. An HTTP request
is sent by a client to the server which then returns a
response. Though HTTP supports several methods, we will
focus on GET, POST, and PUT. Data is processed based on the
selected method.

The GET method fetches data from the server.


The POST method sends data from the HTML form to the
server to create a resource. PUT method sends data to the
server to create or update a resource. Some developers are
unable to differentiate between the POST and PUT methods.

The PUT method is idempotent. This means calling a PUT


method multiple times will not affect the database because
data is already updated. In contrast, calling a POST method
affects the database because you create multiple objects.
How to create HTML forms
HTML forms can contain special elements such
as buttons, radio buttons, and checkboxes. It, therefore,
becomes easy for the user to interact with the webpage.
Forms should be user-friendly. This means that a user with no
technical skills should be able to use it.

Forms are defined by the <form><\form> tags. The form tag


surrounds all the inputs. It also gives instructions about how
and where to submit the form. The HTML form sends data to
your PHP script using either POST or GET methods.

Here is an example of a form that submits data to a file


named index.php. To have a complete source code, use this
HTML code and change the method to either POST or GET
where necessary.
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTML Form</title>
</head>
<body>
<h1>HTML Form</h1>
<form method="" action="index.php">
Name: <input type="text" name="name"><br><br/>
Email: <input type="text" name="email"><br/>
<br/>
<input type="submit" value="submit" >
</form>
</body>
</html>

The output for the above code is as shown in the screenshot


below.
The action identifies the page where the form input is
submitted. Data can be submitted on the same page as the
form or on a different page. The method specifies how data is
processed. This can be POST, GET, or PUT. The GET method
collects data from the server and sends it in the URL. The
data submitted via the POST method is stored in the HTTP
request body and cannot be seen on the URL.

POST method
POST is a superglobal method, which collects form data and
submits it to the HTTP server. The data entered is encoded,
and the content is hidden. POST method has a global scope,
and data is accessed from any script.

The POST method is preferred because data sent through it is


not visible in the URL. The POST method is also important
because data cannot be decoded by looking into web server
logs.

POST does not have a limitation on the amount of data sent


from the form. This is because data is submitted via the body
of the HTTP request. The POST method is appropriate for
a login form.

Processing the form data (PHP


script)
The PHP code below can be used to process input from an
HTML form with the POST method. The code should be put in
the script, which is the form target.

It can be in the same script where the HTML form is, or it can
be on a different script. In this case, we will have the PHP
code in the same script as the HTML form.
<?php
# Check if name and email fileds are empty
if(empty($_POST['name']) && empty($_POST['email'])){
# If the fields are empty, display a message to the user
echo " <br/> Please fill in the fields";
# Process the form data if the input fields are not empty
}else{
$name= $_POST['name'];
$email= $_POST['email'];
echo ('Your Name is: '. $name. '<br/>');
echo ('Your Email is:' . $email. '<br/>');
}
?>

The output of the code above is as shown in the animation


below.
GET method
GET is the default super global method that collects or
retrieves data from the server. It has a global scope. Thus,
data is accessed from any script in the program. The GET
method submits data in the URL.

Data transferred via this method is visible on the URL of the


HTTP request. The HTTP request can be cached and saved in
the browser history. The disadvantage of the GET method is
that it should not be used with sensitive data such as
passwords because it is not secure.

The GET method has a limitation of the amount of data sent


from the form. The data being sent on the URL depends on
the web server’s operating system and the type of browser.

Most systems have a limit of 255 characters. The best


example of using the GET method is with the search engine
forms. The code below can be used to process an HTML form
with a method set as GET.
<?php
# Check if name and email fileds are empty
if(empty($_GET['name']) && empty($_GET['email'])){
# If the fields are empty, display a message to the user
echo "Please fill in the fields";
# Process the form data if the input fields are not empty
}else{
$name= $_GET['name'];
$email= $_GET['email'];
echo ('Welcome: '. $name. '<br/>');
echo ('This is your email address:' . $email. '<br/>');
}
?>
Here is the output of the GET method example.

Tabular comparison of GET and


POST methods
POST Method GET Method
Bookmarking the results is not possible. Results can be bookmarked.
Data do not remain in the browser Data remain in browser history.
history. It’s hidden.
The performance is low because POST The performance is high because of the simple
cannot decode the data. nature of displaying data.
It is more secure It is less secure
Do not limit the amount of data sent to Limit the amount of data sent to the server.
the server.
It works with sensitive data. It cannot work with sensitive data.

PHP Global Variables –


Superglobals
Some predefined variables in PHP are "superglobals", which means that they are
always accessible, regardless of scope - and you can access them from any
function, class or file without having to do anything special.

The PHP superglobal variables are:

 $GLOBALS
 $_SERVER
 $_REQUEST
 $_POST
 $_GET
 $_FILES
 $_ENV
 $_COOKIE
 $_SESSION

PHP $GLOBALS
$GLOBALS is a PHP super global variable which is used to access global
variables from anywhere in the PHP script (also from within functions or
methods).

PHP stores all global variables in an array called $GLOBALS[index].


The index holds the name of the variable.

The example below shows how to use the super global variable $GLOBALS:

Example
<?php
$x = 75;
$y = 25;

function addition() {
$GLOBALS['z'] = $GLOBALS['x'] + $GLOBALS['y'];
}

addition();
echo $z;
?>

In the example above, since z is a variable present within the $GLOBALS array,
it is also accessible from outside the function!

OUTPUT:

100

PHP $_SERVER
$_SERVER is a PHP super global variable which holds information about headers,
paths, and script locations.

The example below shows how to use some of the elements in $_SERVER:
Example
<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_REFERER'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
?>

OUTPUT:

/demo/demo_global_server.php
35.194.26.41
35.194.26.41
https://tryphp.w3schools.com/showphp.php?filename=demo_global_server
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0
/demo/demo_global_server.php

The following table lists the most important elements that can go inside
$_SERVER:

Element/Code Description

$_SERVER['PHP_SELF'] Returns the filename of the currently executing


script

$_SERVER['SERVER_NAME'] Returns the name of the host server (such as


www.w3schools.com)
$_SERVER['SERVER_PROTOCOL'] Returns the name and revision of the information
protocol (such as HTTP/1.1)

$_SERVER['REQUEST_METHOD'] Returns the request method used to access the


page (such as POST)

$_SERVER['QUERY_STRING'] Returns the query string if the page is accessed via


a query string

$_SERVER['HTTP_HOST'] Returns the Host header from the current request

$_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not


reliable because not all user-agents support it)

$_SERVER['HTTPS'] Is the script queried through a secure HTTP


protocol

$_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is


viewing the current page

$_SERVER['REMOTE_HOST'] Returns the Host name from where the user is


viewing the current page

$_SERVER['SCRIPT_NAME'] Returns the path of the current script


$_SERVER['SCRIPT_URI'] Returns the URI of the current page

PHP $_REQUEST
PHP $_REQUEST is a PHP super global variable which is used to collect data after
submitting an HTML form.

The example below shows a form with an input field and a submit button. When
a user submits the data by clicking on "Submit", the form data is sent to the file
specified in the action attribute of the <form> tag. In this example, we point to
this file itself for processing form data. If you wish to use another PHP file to
process form data, replace that with the filename of your choice. Then, we can
use the super global variable $_REQUEST to collect the value of the input field:

Example
<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">


Name: <input type="text" name="fname">
<input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_REQUEST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>

</body>
</html>
OUTPUT:

Submit
Name:

PHP $_POST
PHP $_POST is a PHP super global variable which is used to collect form data
after submitting an HTML form with method="post". $_POST is also widely used
to pass variables.

The example below shows a form with an input field and a submit button. When
a user submits the data by clicking on "Submit", the form data is sent to the file
specified in the action attribute of the <form> tag. In this example, we point to
the file itself for processing form data. If you wish to use another PHP file to
process form data, replace that with the filename of your choice. Then, we can
use the super global variable $_POST to collect the value of the input field:

Example
<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">


Name: <input type="text" name="fname">
<input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>

</body>
</html>
OUTPUT:

Submit
Name:

PHP $_GET
PHP $_GET is a PHP super global variable which is used to collect form data after
submitting an HTML form with method="get".

$_GET can also collect data sent in the URL.

Assume we have an HTML page that contains a hyperlink with parameters:

<html>
<body>

<a href="test_get.php?subject=PHP&web=W3schools.com">Test $GET</a>

</body>
</html>

When a user clicks on the link "Test $GET", the parameters "subject" and "web"
are sent to "test_get.php", and you can then access their values in
"test_get.php" with $_GET.

The example below shows the code in "test_get.php":

Example
<html>
<body>

<?php
echo "Study " . $_GET['subject'] . " at " . $_GET['web'];
?>

</body>
</html>

OUTPUT:
Test & GET

When u click at above link you get:

Study PHP at W3schools.com

Introduction
The global predefined variable $_FILES is an associative array containing items
uploaded via HTTP POST method. Uploading a file requires HTTP POST method form
with enctype attribute set to multipart/form-data.
$HTTP_POST_FILES also contains the same information, but is not a superglobal, and
now been deprecated
The _FILES array contains following properties −
$_FILES['file']['name'] - The original name of the file to be uploaded.
$_FILES['file']['type'] - The mime type of the file.
$_FILES['file']['size'] - The size, in bytes, of the uploaded file.
$_FILES['file']['tmp_name'] - The temporary filename of the file in which the uploaded
file was stored on the server.
$_FILES['file']['error'] - The error code associated with this file upload.
Following test.html contains a HTML form whose enctype is set to multiform/form-data.
It also has an input file element which presents a button on the form for the user to
select file to be uploaded.
<form action="testscript.php" method="POST"
enctype="multipart/form-data">
<input type="file" name="file">
<input type ="submit" value="submit">
</form>
The PHP script is as follows:

Example
<?php
echo "Filename: " . $_FILES['file']['name']."<br>";
echo "Type : " . $_FILES['file']['type'] ."<br>";
echo "Size : " . $_FILES['file']['size'] ."<br>";
echo "Temp name: " . $_FILES['file']['tmp_name'] ."<br>";
echo "Error : " . $_FILES['file']['error'] . "<br>";
?>

Output
This will produce following result −
Filename: hello.html
Type : text/html
Size : 56
Temp name: C:\xampp\tmp\php32CE.tmp
Error : 0

How to read user or console input in PHP ?

In PHP, the console is a command-line interface, which is also


called interactive shell. We can access it by typing the following
command in a terminal:
php -a
If we type any PHP code in the shell and hit enter, it is executed
directly and displays the output or shows the error messages in case of
any error.

In this article, We will discuss two methods for reading console or user
input in PHP:
Method 1: Using readline() function is a built-in function in PHP.
This function is used to read console input.
The following things can be achieved by readline() function:

 Accept a single input by prompting the user:


 PHP
<?php

// For input

// Hello World

$a = readline('Enter a string: ');

// For output

echo $a;

?>

Output:
Enter a string: GeeksforGeeks
GeeksforGeeks
 By default, the data type of the variable accepted through readline()
function is string. So for any other data type, we have
to typecast it explicitly as described below.

 PHP

<?php
// Input section

// $a = 10

$a = (int)readline('Enter an integer: ');

// $b = 9.78

$b = (float)readline('Enter a floating'

. ' point number: ');

// Entered integer is 10 and

// entered float is 9.78

echo "Entered integer is " . $a

. " and entered float is " . $b;

?>

Output:
Enter an integer: 10
Enter a floating point number: 9.78
Entered integer is 10 and entered float is 9.78
 We can achieve the same things without prompting the user
also:
$a = readline();
 In this case, as soon as the user hits enter, the entered value is
stored in the variable a.
 Accept multiple space separated inputs: For this, we use
another function explode() together with readline(). The first
argument of explode() is the delimiter we want to use. In the above
example, the delimiter is space. The second argument is
the readline() function. Here also the data type of $var1 and $var2
will be string. So we have to separately typecast them for other data
types. In the above example, the typecasting is shown for integers.
 PHP

<?php

// Input 10 20

list($var1, $var2)

= explode(' ', readline());

// Typecasting to integers

$var1 = (int)$var1;

$var2 = (int)$var2;

// Printing the sum of var1 and var2.

// The sum of 10 and 20 is 30

echo "The sum of " . $var1 . " and "


. $var2 . " is " . ($var1 + $var2);

?>

Output:
The sum of 10 and 20 is 30

 We can also read an array through explode():


 PHP

<?php

// For input

// 1 2 3 4 5 6

$arr = explode(' ', readline());

// For output

print_r($arr);

/*Array

[0] => 1
[1] => 2

[2] => 3

[3] => 4

[4] => 5

[5] => 6

)*/

?>

Output:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Method 2: Using fscanf() function works same as the fscanf() function
in C. We can read 2 integers from Keyboard(STDIN) as below:
 This is different from the previous method

 PHP

<?php
// Input 1 5

fscanf(STDIN, "%d %d", $a, $b);

// Output

// The sum of 1 and 5 is 6

echo "The sum of " . $a . " and "

. $b . " is " . ($a + $b);

?>

Output:
The sum of 1 and 5 is 6
Comparison between two methods:
 No need to use explicit typecasting for fscanf() function, because
it is done by the format specifiers , e.g. %d, %f, %c etc.
 scanf() function is much faster than the readline() function.
How to Use PHP in
HTML English

In this article, I'll show you how to use PHP code in your HTML pages. It’s
aimed at PHP beginners who are trying to strengthen their grip on the world's
most popular server-side scripting language.

Again, PHP is a server-side scripting language. That means a PHP script is


executed on the server, the output is built on the server, and the result is sent
as HTML to the client browser for rendering. It's natural to mix PHP and
HTML in a script, but as a beginner, it’s tricky to know how to combine the
PHP code with the HTML code.
Different Ways to Combine PHP
and HTML
Broadly speaking, when it comes to using PHP in HTML, there are two
different approaches. The first is to embed the PHP code in your HTML file
itself with the .html extension—this requires a special consideration, which
we’ll discuss in a moment. The other option, the preferred way, is to combine
PHP and HTML tags in .php files.

Since PHP is a server-side scripting language, the code is interpreted and run
on the server side. For example, if you add the following code in
your index.html file, it won’t run out of the box.

<!DOCTYPE html>

<html>

<head>

<title>Embed PHP in a .html File</title>

</head>

<body>

<h1><?php echo "Hello World" ?></h1>

</body>

</html>

The above example outputs the following in your browser:

<?php echo "Hello World" ?>


So as you can see, by default, PHP tags in your .html document are not
detected, and they're just considered plain text, outputting without parsing.
That's because the server is usually configured to run PHP only for files with
the .php extension.

If you want to run your HTML files as PHP, you can tell the server to run
your .html files as PHP files, but it's a much better idea to put your mixed
PHP and HTML code into a file with the .php extension.

How to Add PHP Tags in Your


HTML Page
When it comes to integrating PHP code with HTML content, you need to
enclose the PHP code with the PHP start tag <?php and the PHP end tag ?> .
The code wrapped between these two tags is considered to be PHP code, and
thus it'll be executed on the server side before the requested file is sent to the
client browser.

Let’s have a look at a very simple example, which displays a message using
PHP code. Create the index.php file with the following contents under your
document root.

<!DOCTYPE html>

<html>

<head>
<title>How to put PHP in HTML - Simple Example</title>

</head>

<body>

<h1><?php echo "This message is from server side." ?></h1>

</body>

</html>

The important thing in the above example is that the PHP code is wrapped by
the PHP tags.

The output of the above example looks like this:

And, if you look at the page source, it should look like this:

As you can see, the PHP code is parsed and executed on the server side, and
it's merged with HTML before the page is sent to the client browser.
Let’s have a look at another example:

<!DOCTYPE html>

<html>

<head>

<title>How to put PHP in HTML- Date Example</title>

</head>

<body>

<div>This is pure HTML message.</div>

<div>Next, we’ll display today’s date and day by PHP!</div>

<div>

Today’s date is <b><?php echo date('Y/m/d') ?></b> and it’s a <b><?php echo

date(‘l’) ?></b> today!

</div>

<div>Again, this is static HTML content.</div>

</body>

</html>

This will output the current date and time, so you can use PHP code between
the HTML tags to produce dynamic output from the server. It’s important to
remember that whenever the page is executed on the server side, all the code
between the <?php and ?> tags will be interpreted as PHP, and the output
will be embedded with the HTML tags.

In fact, there’s another way you could write the above example, as shown in
the following snippet.

<!DOCTYPE html>

<html>

<head>
<title>How to put PHP in HTML- Date Example</title>

</head>

<body>

<div>This is pure HTML message.</div>

<div>Next, we’ll display today’s date and day by PHP!</div>

<div>

<?php

echo 'Today’s date is <b>' . date('Y/m/d') . '</b> and it’s a

<b>'.date('l').'</b> today!';

?>

</div>

<div>Again, this is static HTML content.</div>

</body>

</html>

In the above example, we’ve used the concatenation feature of PHP, which
allows you to join different strings into one string. And finally, we’ve used
the echo construct to display the concatenated string.

The output is the same irrespective of the method you use, as shown in the
following screenshot.
The overall structure of the PHP page combined with HTML and PHP code
should look like this:

<!DOCTYPE html>

<html>

<head>

<title>...</title>

</head>

<body>

HTML...

<?php PHP code ... ?>

HTML...

<?php PHP code ... ?>

HTML...

</body>

</html>
How to Use PHP Loops in Your
HTML Page
Iterating through the arrays to produce HTML content is one of the most
common tasks you'll encounter while writing PHP scripts. In this section,
we’ll see how you could iterate through an array of items and generate
output.

In this example, we’ll initialize the array with different values at the
beginning of the script itself.

Go ahead and create a PHP file with the following contents.

<!DOCTYPE html>

<html>

<head>

<title>How to put PHP in HTML - foreach Example</title>

</head>

<body>

<?php

$employees = array(‘John’, ‘Michelle’, ‘Mari’, ‘Luke’, ‘Nellie’);

?>

<h1>List of Employees</h1>

<ul>

<?php foreach ($employees as $employee) { ?>

<li><?php echo $employee ?></li>

<?php } ?>

</ul>
</body>

</html>

Firstly, we’ve initialized the array at the beginning of our script. Next, we’ve
used the foreach construct to iterate through the array values. And finally,
we’ve used the echo construct to display the array element value.

And the output should look like this:

The same example with a while loop looks like this:

<!DOCTYPE html>
<html>

<head>

<title>How to put PHP in HTML - foreach Example</title>

</head>

<body>

<?php

$employees = array(‘John’, ‘Michelle’, ‘Mari’, ‘Luke’, ‘Nellie’);

$total = count($employees);

?>

<h1>List of Employees</h1>

<ul>

<?php

$i = 0;

?>

<?php while ($i < $total) { ?>

<li><?php echo $employees[$i] ?></li>

<?php ++$i ?>

<?php } ?>

</ul>

</body>

</html>

And the output will be the same. So that’s how you can
use foreach and while loops to generate HTML content based on PHP
arrays.
How to Use PHP Short Tags
In the examples we’ve discussed so far, we’ve used the <?php as a starting
tag everywhere. In fact, PHP comes with a variation, <?= , which you could
use as a short-hand syntax when you want to display a string or value of the
variable.

Let’s revise the example with the short-hand syntax which we discussed
earlier.

<!DOCTYPE html>

<html>

<head>

<title>How to put PHP in HTML - Simple Example</title>

</head>

<body>

<h1><?= "This message is from server side." ?></h1>

</body>

</html>
As you can see, we can omit the echo or print construct while displaying a
value by using the shorthand syntax. The shorthand syntax is short and
readable when you want to display something with echo or print .

Using hidden field in PHP language


A hidden field is similar to a text field. The hidden field in a form are
embedded in the HTML source code of the form. The difference is that
the user cannot view the hidden field and its content. A hidden field
enables the web developer to pass variables with values from one form
to another without requiring to re-enter the information.

The Syntax to define a hidden field is as follows:

< INPUT TYPE = “HIDDEN” NAME=” hidden1” VALUE=” PHP MESSAGE”


>

Where,

TYPE — specifies that the field is hidden

NAME — specifies the name of the hidden field

VALUE – specifies the value as it appears on the form

To use hidden fields and pass the name of the continents in a PHP
script.

Steps are as follows:

<html>

<head>

<title>Hidden Field Page Title</title>

</head>

<body>

<form method=”GET” action=”content.php”>

Specifies the content:

<select type=”LISTBOX” NAME=”content”>


<option>ASIA</option>

<option>AUSTRALIA</option>

<option>EUROPE</option>

</select> <br /> <br />

<input type=”hidden” name=”ASIA”>

<input type=”hidden” name=”AUSTRALIA”>

<input type=”hidden” name=”EUROPE”> <br />

<input type=”submit”>

</form>

</body>

</html>

How to make a redirect in PHP?



Redirection from one page to another in PHP is commonly achieved
using the following two ways:
Using Header Function in PHP:
The header() function is an inbuilt function in PHP which is used to
send the raw HTTP (Hyper Text Transfer Protocol) header to the client.
Syntax:
header( $header, $replace, $http_response_code )
Parameters: This function accepts three parameters as mentioned
above and described below:

 $header: This parameter is used to hold the header string.


 $replace: This parameter is used to hold the replace parameter
which indicates the header should replace a previous similar header,
or add a second header of the same type. It is optional parameter.
 $http_response_code: This parameter hold the HTTP response
code.
Below program illustrates the header() function in PHP:
Program:
 php

<?php

// Redirect browser

header("Location: http://www.geeksforgeeks.org");

exit;

?>

Redirection is done by outputting a Location using PHP using the header() function.
Here's how to redirect to a page called thanks.html:
header( "Location: thanks.html" );
Don't output any content to the browser via echo() or print(), or by including HTML
markup outside the <?php ... ?> tags before calling header().

Example
Here's a quick example of a form handler script that redirects to a thank - you page:

<?php //from ww w .j a va2 s .c om


if ( isset( $_POST["submitButton"] ) ) {
// (deal with the submitted fields here)
header( "Location: thanks.html" );
exit;
} else {
displayForm();
}
function displayForm() {
?>
<!DOCTYPE html5>
<html>
<body>
<form action="index.php" method="post">
<label for="firstName">First name</label>
<input type="text" name="firstName" id="firstName" value="" />
<label for="lastName">Last name</label>
<input type="text" name="lastName" id="lastName" value="" />
<input type="submit" name="submitButton" id="submitButton" value=
"Send Details" />
</form>
</body>
</html>
<?php
}
?>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy