Skip to content

Instantly share code, notes, and snippets.

@rifki
Created September 21, 2012 09:56
Show Gist options
  • Save rifki/3760700 to your computer and use it in GitHub Desktop.
Save rifki/3760700 to your computer and use it in GitHub Desktop.
GET Request
<?php
/**
* maintain....
* pages for GET request
*
* @author rifki
*/
class SayHello
{
private $firstName;
private $lastName;
private $fullName;
public $page = '?page';
public $form = array();
public function setFistName($fistName)
{
$this->firstName = $fistName;
}
public function setLastName($lastName)
{
$this->lastName = $lastName;
}
public function getFirstName()
{
return $this->firstName;
}
public function getLastName()
{
return $this->lastName;
}
public function getFullName($firstName, $lastName)
{
echo "<br />";
// echo "Full Name : ". $this->fullName = $firstName . $lastName . "<br />";
// echo "First Name : ". $firstName."<br />";
// echo "Last Name : ". $lastName . "<br />";
// return "Full Name : ".$firstName . $lastName;
$this->firstName = $firstName;
$this->lastName = $lastName;
$this->fullName = $firstName . $lastName;
return $this->fullName;
}
/*********************************************/
public function sayHello($firstName, $lastName)
{
$this->firstName = $firstName;
$this->lastName = $lastName;
echo $this->fullName = (string) $firstName . $lastName;
}
public function sayHelloNaN()
{
if (isset($this->firstName) AND (isset($this->lastName))) {
if (empty($this->firstName)) {
echo "Please try again for input your <strong>first name</strong>";
exit();
}
if (empty($this->lastName)) {
echo "Please try again for input your <strong>last name</strong>";
exit();
}
if (preg_match("/[0-9]/", $this->firstName, $this->lastName)) {
echo "You must be alphabet";
exit();
}
}
}
public function form()
{
$form = "<form name=\"form\" action=\"?page=say\" method=\"post\">";
$form .= "First Name : <input type=\"text\" name=\"firstname\">";
$form .= "Last Name : <input type=\"text\" name=\"lastname\">";
$form .= "<input type=\"submit\" name=\"submit\"></form>";
return $form;
}
public function getRequestSay()
{
$page = $_GET['page'];
if ($page == 'say') {
$this->firstName = $_POST['firstname'];
$this->lastName = $_POST['lastname'];
$submit = $_POST['submit'];
if ($submit) {
$this->sayHello($this->firstName, $this->lastName);
$this->sayHelloNaN($this->firstName, $this->lastName);
exit();
}
} else {
echo "This page for <strong>{$page}</strong> is not found! <br />
Request: "."<code>".$_SERVER[REQUEST_URI]."</code>"
;
}
}
}
$say = new SayHello();
echo $say->form();
$say->getRequestSay();
echo $say->getFullName('Muhamad', 'Rifki');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment