2. post 방식. -php-

2017. 3. 9. 09:42 from COMPUTER/php

2. post 방식. -php-

 

-post방식

-이벤트 핸들러

 

get방식 복습:

exam1.php

<form name="calc" method="get/post" action="calc.php">

<!--aaaa -->

a: <input type="text" name="a" />

b: <input type="text" name="b" />

<input type="submit" name="submit" value="계산" />

</form>

 

calc.php

<?

echo $_GET[a]."+";

echo $_GET[b]."<br>";

echo $_GET[a] + $_GET[b]."<br>";

echo "submit=".$_GET[submit];

?>

//주소창에서 전달되는 변수들

http:// ~~~ /study/calc.php?a=234&b=123&submit=계산

 

//결과

234+123

357

submit=계산

 

post를 이용한 변수값 전달:

get 방식과 같고 단지 getpost로 바꾸면 된다.

$_GET['변수명']$_POST['변수명']으로 바꾼다.

"GET""POST"는 대문자로 써야한다.

post를 이용하면 주소창에 변수값이 뜨지 않는다.

calc.php에 아래 코드를 추가하면 돌아가기 버튼을 만들면 바로 전 페이지로 돌아간다.

이때 입력했던 값이 그대로 나타나네...

<input type="button" value="돌아가기" onclick="history.back();" />

여기서 onclick="history.back();" 은 이벤트 핸들러이다. 이런 기법은 다양하게 응용될 수 있으니 잘 숙지해야 할 것.

 

calc.php

<?

echo $_POST[a]."+";

echo $_POST[b]."<br>";

echo $_POST[a] + $_POST[b]."<br>";

echo "submit=".$_POST[submit];

?>

<input type="button" value="돌아가기" onclick="history.back();" />

 

이벤트 핸들러 :

onabort: 이미지 로딩이 중단될 경우 실행된다.

onblur: 엘리먼트가 입력 포커스를 잃어버릴 경우 실행된다.

onchange: 폼 엘리먼트가 포커스를 잃고 값이 변경될 경우 실행된다.

onclick: 마우스 버튼이 눌렸다 떼어질 때 실행된다. mouseup 이벤트가 이어서 발생한다. 기본 동작 방식을 취소하려면 false를 반환한다.

ondblclick: 마우스가 더블클릭될 때 실행된다.

onerror: 이미지 로딩 오류가 일어날 경우 실행된다.

onfocus: 엘리먼트가 입력 포커스를 얻을 경우 실행된다.

onkeydown: 키가 눌렸을 때 실행된다. 취소하려면 false를 반환한다.

onkeypress: 키가 눌렸을 때 실행된다. keydown 이벤트가 이어서 발생한다. 취소하려면 false를 반환한다.

onkeyup: 키에서 손을 뗐을 때 실행된다. keypress 이벤트가 이어서 발생한다.

onmousedown: 마우스 버튼이 눌렸을 때 실행된다.

onmousemove: 마우스가 이동할 경우 실행된다.

onmouseout: 마우스가 엘리먼트에서 벗어났을 때 실행된다.

onmouseover: 마우스가 엘리먼트 위로 이동할 때 실행된다.

onmouseup: 마우스 버튼에서 손을 뗐을 때 실행된다.

onresize: 윈도우 크기가 변경될 경우 실행된다.

onselect: 텍스트가 선택됐을 때 실행된다.

onreset: 폼 초기화가 요청됐을 때 실행된다. 초기화를 방지하려면 false를 반환한다.

onsubmit: 폼 제출이 요청됐을 때 실행된다. 제출을 방지하려면 false를 반환한다.

onload: 문서 로딩이 완료됐을 때 실행된다.

onunload: 문서나 프레임셋이 사라졌을 때 실행된다.

사용 예:

<input type="button" value="Press Me" onclick="alert('thanks');">

 

<form action="processform.action" onsubmit="return validateForm();">

 

<body onload="startApp()">

'COMPUTER > php' 카테고리의 다른 글

5. 배열 변수 -php-  (0) 2017.03.11
4. for문 -php-  (0) 2017.03.10
3. 연산자. -php-  (0) 2017.03.10
1. php의 기본. -php-  (0) 2017.03.08
php class 특강  (0) 2017.03.07
Posted by star story :

Snippet :: Code View :: "+location.href+'
'+b+"

");top.consoleRef.document.close()}$(".snippet-container").each(function(b){$(this).find("a.snippet-text").click(function(){var d=$(this).parents(".snippet-wrap").find(".snippet-formatted");var c=$(this).parents(".snippet-wrap").find(".snippet-textonly");d.toggle();c.toggle();if(c.is(":visible")){$(this).html("html")}else{$(this).html("text")}return false});$(this).find("a.snippet-window").click(function(){var c=$(this).parents(".snippet-wrap").find(".snippet-textonly").html();a(c);$(this).blur();return false})});$(".snippet-toggle").each(function(b){$(this).click(function(){$(this).parents(".snippet-container").find(".snippet-wrap").toggle()})})});