0

I've a form class I'm calling from display() method.Then display() method getting value of name,email,password etc by $_POST method.But I want to getting the name of value with out $_POST.And also want to escape html.Is it possible to get value with out $_POST then escape html. Like this formet classname::get('name');

public function display()
{
    $newform=new Form();

 // Input::get('name');

    $newform->setvalue($_POST['name']);
    $name=$newform->getvalue();

    $newform->setvalue($_POST['email']);
    $b=$newform->getvalue();

    $newform->setvalue($_POST['pass']);
    $c=$newform->getvalue();
    $newform->setvalue($_POST['rpass']);
    $d=$newform->getvalue();
    $newform->setvalue($_POST['phone']);
    $e=$newform->getvalue();
}


<?php 

class Form
{
private $value;


public  function setvalue($value)
{
    $this->value=$value;
}


public function getvalue()
    {
        $a=$this->value;
        return $a;
    }
}
  • So you basically want to retrieve POST data without using $_POST? – Andrei P. Mar 16 '15 at 09:09
  • Yse.Is it possible?if not how can I filter $_POST?@Andrei P –  Mar 16 '15 at 09:10
  • Not that I'm aware of, no. But for what do you need this anyway? [Read this](http://stackoverflow.com/questions/129677/whats-the-best-method-for-sanitizing-user-input-with-php) for data sanitation. It explains it a lot better than I can. – Andrei P. Mar 16 '15 at 09:12

2 Answers2

0

Possible, But what is wrong with $_POST ?

Without using $_POST you can get the form data directly from the HTTP request header. Check this official documentation

http://php.net/manual/en/function.http-get-request-body.php

Navneet Singh
  • 1,218
  • 11
  • 17
0

From what i understand you don't like to use $_POST in your code but willing to have a class dedicated to get the $_POST value. So I have created a class that takes the post and returns an array of the $_POST values.

$newform = new Form();
echo "<pre>";
var_dump($newform->getValue());


class Form{
    private $value = array();
    function __construct(){
        foreach($_POST as $k=>$v)
            $this->value[$k] = $v;// here you can use some validation or escapes

    }
    public function getValue(){
        return $this->value;
    }
}
itssajan
  • 820
  • 8
  • 24