Jump to content
xisto Community
Sign in to follow this  
flashy

Php - Forms, Date And Include Working with POST and GET and also the Date() function

Recommended Posts

/--------PHP FORMS, DATE AND INCLUDE TUTORIAL BY FLASHY--------\

Hi and welcome to my tutorial.
I will show you how to make simple PHP forms with the POST and GET statements.
I will also show show you the Date() function too, aswell as the include() function.

OK, so first you need a good understanding of HTML, and you need to create your form using that. So lets start off with the HTML form.

1. Create a page called form.html.

2. Insert your standard tags like:

<html><head><title>Working with php forms.</title></head><body></body><html>
(to save you time just copy it all out so you dont have to write that)

3. Now lets start with our form. We are going to use the post method first.
<form method="post" action="process.php">

meaning of the code
method: POST or GET - if the method is GET then the values you input will be desplayed as variables in the address bar. If the method is POST then it is not. (post is should be done when using registration forms and such as it is more secure.)
action: This will be what the browser will redirect you to.

4. OK i hope you got all that - Now lets insert a text box
<input type="text" name="name" /><br />

Basically we called the textbox "name". And put a brake at the bottom so it leaves a space.

5. Insert a dropdown.
<select name="pet">	<option>Dog</option>	<option>Rabbit</option>	<option>Hamster</option>	<option>Cat</option>	<option>Fish</option></select><br />

We called the dropdown "pet"

6. Now a radio list.
<input type="radio" name="ageGroup" value="110">1-10</input><br /><input type="radio" name="ageGroup" value="1120">11-20</input><br /><input type="radio" name="ageGroup" value="2130">21-30</input><br /><input type="radio" name="ageGroup" value="31">31+</input><br />

Right heres a complicated one. We named them ageGroup, and we change the value to what we want the text to be. But when we come to get the data you should see the "?ageGroup="110"" because we set the name and the value. Basically "Value" is the text inside it.

7. Now finish off with a submit.
<input type="submit" name="submit" value="submit" />

8. And finish off the form
</form>

9. So all together it should look like this

<html><head><title>Working with php forms.</title></head><body>	<form method="post" action="process.php">		<input type="text" name="name" />	<br />		<select name="pet">			<option>Dog</option>			<option>Rabbit</option>			<option>Hamster</option>			<option>Cat</option>			<option>Fish</option>		</select>	<br />		<input type="radio" name="ageGroup" value="110">1-10</input><br />		<input type="radio" name="ageGroup" value="1120">11-20</input><br />		<input type="radio" name="ageGroup" value="2130">21-30</input><br />		<input type="radio" name="ageGroup" value="31">31+</input>	<br /></body><html>

(its better to paragraph when programming)

________________________________________

Now we are going to go and make the PHP form.

First of all make a file called "Process.php" and place in all the standard tags
<html><head><title>Working with php forms.</title></head><body></body><html>

1. Now in the body section you need to start off your PHP
<?PHP

2. And finish it
?>

3. Now i know i am making this tutorial a bit hard for you to read so i am going to place al of the code then explain it below...
$name = $_POST['name];$pet = $_POST['pet'];$ageGroup = $_POST['ageGroup'];	echo "Your name is " . $name; . "<br />";	echo "Your favourite pet is " . $pet . "<br />";	echo "Your age group is " . $ageGroup . "<br />;

We called the varables by $_POST - if you had a GET then you would use $_GET
Then we echoed (or printed) "Your name is "... and placed a "." to tell php it as an AND. then called the variable $name and print it out.
And then i placed a <br /> to break it out.

OK I hope you got most of that.

_______________________

Now i will show you the date functions.

The date function uses letters of the alphabet to represent various parts of a date and time format so we need to know what they are first.

echo date("d/m/y");

Would then display

8/3/08

here are the full timestamps from PHP.net

Time: a: am or pm depending on the time
A: AM or PM depending on the time
g: Hour without leading zeroes. Values are 1 through 12.
G: Hour in 24-hour format without leading zeroes. Values are 0 through 23.
h: Hour with leading zeroes. Values 01 through 12.
H: Hour in 24-hour format with leading zeroes. Values 00 through 23.
i: Minute with leading zeroes. Values 00 through 59.
s: Seconds with leading zeroes. Values 00 through 59.
Day:
d: Day of the month with leading zeroes. Values are 01 through 31.
j: Day of the month without leading zeroes. Values 1 through 31
D: Day of the week abbreviations. Sun through Sat
l: Day of the week. Values Sunday through Saturday
w: Day of the week without leading zeroes. Values 0 through 6.
z: Day of the year without leading zeroes. Values 0 through 365.
Month:
m: Month number with leading zeroes. Values 01 through 12
n: Month number without leading zeroes. Values 1 through 12
M: Abbreviation for the month. Values Jan through Dec
F: Normal month representation. Values January through December.
t: The number of days in the month. Values 28 through 31.
Year:
L: 1 if it's a leap year and 0 if it isn't.
Y: A four digit year format
y: A two digit year format. Values 00 through 99.

Notice from jlhaslip:
added quote tags to the list of time/date parameters.


____________________________

Now i will show you how to use Include

It is quite easy - about as easy as the Date function.

to join your file

include("index.htm"); //Or anyother page

_______________________________

Hope i helped you a bit - certainly helped me.

Thanks comments welcome

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.