2013-05-19 3 views
-1

안녕하세요, 저는 "Form two is here"메시지가 다음 코드에 표시되지 않는 이유에 대해 단서를 알려줍니다. 나는 다음과 같은 구조로 긴 코드를 작성했다. 양식에 도움두 번째 양식 제출 캡처 문제 - PHP

<DOCTYPE html> 
<html> 
<head><title></title> 
</head> 
<body> 
<div id="one" style="width:300px; background:gray;"> 
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> 
<input type="text" name="txt1" id="txt1"> 
<input type="submit" name="sendone" id="sendone" value="One"> 
</form> 
</div> 

<div id="two" style="width:300px; background:yellow;"> 
<?php 
if(isset($_POST['sendone'])) 
{echo "<input type='submit' name='sendtwo' id='sendtwo' value='Two'>";} 

if(isset($_POST['sendtwo'])) 
{echo "Form two is here!"; return;} 
?> 
</div> 
</body> 
</html> 
+1

sendtwo라는 이름의 버튼을 제출 양식에 속하지 않아. –

+0

@Baba 당신이 그 선을 완전히 읽고 당신이 영어를 이해하기를 진심으로 바랍니다. "다음 구조에 긴 코드를 작성했습니다" –

답변

1

주셔서 감사합니다 당신은 단지 필드 'sendone'을 가지고있다. 다른 하나는 서식 외부에 배치됩니다.

첫 번째 양식을 제출하면 HTML 코드에 두 번째 입력란을 삽입하지만 양식 태그 외부에 배치합니다. 그래서 두 번째로 양식을 제출할 때 요청에 포함되지 않습니다. 모든 입력 필드는 처리를 위해 여는 및 닫는 양식 태그 내에 있어야합니다.

당신은 '형태'태그 내에서 두 번째 양식 입력을 배치해야합니다 :

<DOCTYPE html> 
<html> 
<head><title></title> 
</head> 
<body> 
<div id="one" style="width:300px; background:gray;"> 
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> 
<input type="text" name="txt1" id="txt1"> 
<?php 
if(isset($_POST['sendone'])) 
{echo "<input type='submit' name='sendtwo' id='sendtwo' value='Two'>";} 
?> 
<input type="submit" name="sendone" id="sendone" value="One"> 
</form> 
</div> 

<div id="two" style="width:300px; background:yellow;"> 
<?php 
if(isset($_POST['sendtwo'])) 
{echo "Form two is here!"; return;} 
?> 
</div> 
</body> 
</html> 
+0

Thanks @stefandoorn! –

0

sendtwo이 형태 아니며,`sendtwo`는 않기 때문에 양식을

<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>"> 
    <input type="text" name="txt1" id="txt1"> 
    <input type="text" name="sendtwo" value="I am sendtwo!"> 
    <input type="submit" name="sendone" id="sendone" value="One"> 
</form>