Submit Form 객체를 통해 전달 받은 사용자 입력 값을 처리하는 방법을 안내합니다.
다른 Controller의 Form 객체에서 사용자가 입력한 항목을 Submit Controller를 통해 전달 받고
처리하는 방법을 안내합니다.
아래 예시는 /sign/sign Controller의 Form 객체에서 sign/sign-submit Submit Controller로 전달하는 가정으로 작성된 코드입니다.
Method Utility를 사용하기 위해선 먼저 use 로 Method가 선언되어야 합니다.
아래 코드를 통해 외부 발신처에서 Form 객체가 전달 되었다면 즉시 코드 실행을 중단합니다.
아래 코드를 통해 Request type이 GET 인지 POST인지 검사를 수행 후 조건에 일치하지 않는다면 코드 실행을 즉시 중단합니다.
만약, Request 구분 없이 모든 type의 Request를 허용 하려는 경우 security() 를 제거합니다.
만약, FILE로 전달 받은 값을 변수화 하는 경우 아래와 같이 처리합니다.
좀더 자세한 변수화 및 Validation 처리 방법은 아래 '연관 가이드 바로가기'를 참고 바랍니다.
처리하는 방법을 안내합니다.
Submit Controller 생성
다른 Controller의 Form 객체에서 입력 항목 값을 전달 받을 새로운 Submit Controller를 생성합니다.아래 예시는 /sign/sign Controller의 Form 객체에서 sign/sign-submit Submit Controller로 전달하는 가정으로 작성된 코드입니다.
Controller
/app/sign.php
위와 같이 Form 객체가 생성된 Signin{} 아래에 Sigin_submit{} 를 추가하여 Submit Controller를 생성합니다.
<?php
class Signin extends \Controller\Make_Controller {
public function init()
{
$this->layout()->head('type2');
$this->layout()->view(PH_THEME_PATH.'/html/sign/signin.tpl.php');
$this->layout()->foot();
}
public function make()
{
...
}
public function form()
{
$form = new \Controller\Make_View_Form();
$form->set('type', 'html');
$form->set('action', '/sign/sigin-submit');
$form->run();
}
}
class Sigin_submit {
public function init()
{
}
}
Submit 수행 준비
Method Utility Method를 통해 Submit Controller에서 값을 전달 받습니다.Method Utility를 사용하기 위해선 먼저 use 로 Method가 선언되어야 합니다.
Controller
/app/sign.php
<?php
use Corelib\Method;
class Signin extends \Controller\Make_Controller {
public function init()
{
...
}
public function make()
{
...
}
public function form()
{
$form = new \Controller\Make_View_Form();
$form->set('type', 'html');
$form->set('action', '/sign/sigin-submit');
$form->run();
}
}
class Sigin_submit {
public function init()
{
}
}
Referer 검사 수행
Form 객체의 발신처가 내부 호스트인지 검사합니다.아래 코드를 통해 외부 발신처에서 Form 객체가 전달 되었다면 즉시 코드 실행을 중단합니다.
Controller
/app/sign.php
<?php
use Corelib\Method;
class Signin extends \Controller\Make_Controller {
public function init()
{
...
}
public function make()
{
...
}
public function form()
{
$form = new \Controller\Make_View_Form();
$form->set('type', 'html');
$form->set('action', '/sign/sigin-submit');
$form->run();
}
}
class Sigin_submit {
public function init()
{
Method::security('referer');
}
}
Request 검사 수행
Form 객체에서 전달한 Request type를 검사합니다.아래 코드를 통해 Request type이 GET 인지 POST인지 검사를 수행 후 조건에 일치하지 않는다면 코드 실행을 즉시 중단합니다.
Controller
/app/sign.php
GET 만 허용 하려는 경우 아래와 같이 대체합니다.
<?php
use Corelib\Method;
class Signin extends \Controller\Make_Controller {
public function init()
{
...
}
public function make()
{
...
}
public function form()
{
$form = new \Controller\Make_View_Form();
$form->set('type', 'html');
$form->set('action', '/sign/sigin-submit');
$form->run();
}
}
class Sigin_submit {
public function init()
{
Method::security('referer');
Method::security('request_post'); //POST만 허용
}
}
만약, Request 구분 없이 모든 type의 Request를 허용 하려는 경우 security() 를 제거합니다.
Method::security('request_get'); //GET만 허용
Form 입력 항목 변수화
Form 객체에서 전달 받은 입력 항목 값을 Submit Controller에서 Validation 등의 처리가 가능하도록 변수화 합니다.
Controller
/app/sign.php
만약, GET으로 전달 받은 값을 변수화 하는 경우 아래와 같이 처리합니다.
<?php
use Corelib\Method;
class Signin extends \Controller\Make_Controller {
public function init()
{
...
}
public function make()
{
...
}
public function form()
{
$form = new \Controller\Make_View_Form();
$form->set('type', 'html');
$form->set('action', '/sign/sigin-submit');
$form->run();
}
}
class Sigin_submit {
public function init()
{
Method::security('referer');
Method::security('request_post'); //POST만 허용
$req = Method::request('post', 'memberid, memberpwd'); //POST로 넘겨 받은 값을 변수화 처리
}
}
$req = Method::request('get', 'memberid, memberpwd');
$file = Method::request('file', 'profileimg');
연관 가이드 바로가기
Submit시 Form 입력 항목 변수화 및 Validation 처리 방법
