Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Build A Simple PHP Application: Stage 3 Adding A Contact Form

Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 4

Build a Simple PHP Application

Stage 3 Adding a Contact Form


1 Creating Input Fields.mp4
name attr is for the server to recognize which field it is.
Label tag and for attr is to entitle the text field for the user to
see which field it is.
In order for label tag to function, we must use id.
We us table for forms.
2 Woring with Post Variables.mp4
The user fills out information and clicks the send button.
The browser sends request along with some info(input values
to the server.
The server then has access to this info while executing
php code.
Through action attr in form element we can tell the server
where to send our submitted info.
The info we submit through the form will be saved
in the $_POST variable.
var_dump command displays all the possible info associated
with a particular variable.
3 Working with Concatenation and Whitespace.mp4
To define the data we write echo Name: ;
The space is because we want some space between title
and data.
To concatenate something is to put together somethings in a
chain.
period is used for concatenating.

. \n; - To add line breaks.


If we wanted line breaks in the browsers we would need
<br>
But we want line breaks in emails we would use \n
What we see in the source will what we see in the email.
We will use Pre for white space display on browser.
We will assign all variables ot one single email variable.
4 Redirecting After a Form Submission.mp4
What to do next after the form is submitted and the email
server is set.
// is used for comments.
By refreshing the site the browser asks us again to resubmit
the form on which if we say yes, it will send us another email
if no it will give an ugly error message. We don't need this.
We will create this php for redirecting the browser.
Header command is used to redirect the browser.
Now we can move forward or backward skipping
contact-process.php because of Header command.
The problem was that when we first submit the form
and then go to the home page then decide to move back to
where we were the browser will show this message of
re submitting the form and thus send another email. To stop
this we used the Header command which is server commands
to the browser before loading html docs.
PHP first send the email and then redirect the visitor to a
different thank you page instead of showing thankyou on the
same page the form was submitted.
If we do it properly the post submission will not be recorded
as the browser history.
5 Checking the Request Method.mp4

We have used 3 separate PHPs but we will now use 1 PHP for this purpose.
We will use conditionals in one file to activate in each circumstances.
First we deleted the process part from the contact.php
then we copied the code from contact-process.php to contact.php
Now we will add conditionals.
$_SERVER is an array with multiple elements in it. It is used to check
If the Request Method is Post we will send the email.
If the Request Method isn't post the form will be shown normally.
Exit; command ends the code and redirects to the thank you page.
6 Working with Get Variables.mp4
After we submit the form, php sends the email through header command
We need to show Thank you Page.
?status=thanks - ?variable with any name=value
This info is recorded in the special variable $_GET[status] we must
write the same variable name as was written in the code.

You might also like