create a simple form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loyd.augustine
Forum Newbie
Posts: 1
Joined: Sun Aug 31, 2014 9:27 am

create a simple form

Post by loyd.augustine »

Helo. i am learning php, and i need help creating below for. Its simple but i need help.

Create a form that contains:
1. Name, textbox
2. Submit button

If the user inputs the Name textbox and clicks the Submit button, the system must:
1. Display "Good morning, <Name>" if the server time is within 12am-12 noon
2. Display "Hello, <Name>" if the server time is not within 12am-12 noon
<Name> is the value as inputted by the user into the textbox
donny
Forum Contributor
Posts: 179
Joined: Mon Aug 11, 2014 11:18 am

Re: create a simple form

Post by donny »

Form Page

Code: Select all

<form action="process.php" method="post">
Name: <input type="text" name="firstName">
<input type="submit" value="Next">
</form>
process.php

Code: Select all

<?php
date_default_timezone_set('EST'); //Time Zone
$time = date("H"); //Military Time Hour Only
$firstName = $_POST['firstName']; 
$range = range(00,12); 
if(in_array($time, $range)){
echo "Good morning, $firstName";
}
else{
echo "Hello, $firstName";
}
?>

I am pretty new to PHP so there is probably a better way of doing it, but it works.
Post Reply