2014-02-24 2 views
2

저는 C# 배경에서 가져 왔고 PHP에 익숙하지 않았습니다. html 양식은 다음 PHP 파일에 값을 제출하고 어떤 이유로 값이 설정되지 않습니다. 무엇을 잘못하고 있습니까? 당신이 속성 name를 설정하지 않은에서 것을PHP는 html 양식의 매개 변수를 전달합니다

<form action="sendfeedback.php" method="post"> 
    <div><input placeholder="Name" id="txtName" name='txtName' type="text" /></div> 
    <div><input placeholder="Email (Optional)" id="txtEmail" name="txtEmail" type="text" /></div> 
    <div><input placeholder="Application Name (Type in the application name you're using)" id="txtAppName" name="txtAppName" type="text" /></div> 
    <div style="height:4px"></div> 
    <div><textarea placeholder="Comments..." id="txtComment" name='txtComment'></textarea></div> 
    <div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div> 
</form> 
+1

양식을 표시하십시오. –

+1

양식 메서드를 추가하십시오. 게시물은 –

+3

입니다. 양식 필드에 이름, 특히 PHP 스크립트에서 사용하는 이름이 있는지 확인하십시오. – putvande

답변

2

양식 입력이 같은 속성 name을 가져야한다 : 여기

<?php 
include('Mail.php'); 
$recipients = "[email protected]"; 
$name = $_POST["txtName"] ; 
$from = $_POST["txtEmail"] ; 
$subject = $_POST["txtAppName"] ; 
$comments = $_POST["txtComment"] ; 

$headers = array (
    'From' => $from, 
    'To' => $recipients, 
    'Subject' => $subject, 
); 
$body = "Name: ".$name."\r\n"."Comments: "."\r\n".$comments; 
$mail_object =& Mail::factory('smtp', 
    array(
     'host' => 'prwebmail', 
     'auth' => true, 
     'username' => 'username', 
     'password' => 'pass', # As set on your project's config page 
     'debug' => true, # uncomment to enable debugging 
    )); 
$mail_object->send($recipients, $headers, $body); 
?> 

그리고

는 HTML 양식입니다 inputs의 경우 채널 번호가

<form action="sendfeedback.php" method="post"> 
      <div><input name = 'txtName' placeholder="Name" id="txtName" type="text" /></div> 
      <div><input name = 'txtEmail' placeholder="Email (Optional)" id="txtEmail" type="text" /></div> 
      <div><input name ='txtAppName' placeholder="Application Name (Type in the application name you're using)" id="txtAppName" type="text" /></div> 
      <div style="height:4px"></div> 
      <div><textarea name ='txtComment' placeholder="Comments..." id="txtComment"></textarea></div> 
      <div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div> 
     </form> 
1

이유 :

<form action="sendfeedback.php" method="post"> 
      <div><input placeholder="Name" id="txtName" type="text" /></div> 
      <div><input placeholder="Email (Optional)" id="txtEmail" type="text" /></div> 
      <div><input placeholder="Application Name (Type in the application name you're using)" id="txtAppName" type="text" /></div> 
      <div style="height:4px"></div> 
      <div><textarea placeholder="Comments..." id="txtComment"></textarea></div> 
      <div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div> 
     </form> 
1

당신은 당신의 입력의 name 특성을 놓치고 :

1

은 입력 필드에는 이름 속성이 존재하지 않는, 당신은 id 속성을 사용했다,하지만 당신은 양식 값을 게시 name 속성을 사용합니다.

<form action="sendfeedback.php" method="post"> 
     <div><input name="txtName" placeholder="Name" id="txtName" type="text" /></div> 
        ^^^^^^^^^^^^^^ 
     <div><input name="txtEmail" placeholder="Email (Optional)" id="txtEmail" type="text" /></div> 
     <div><input name="txtAppName" placeholder="Application Name (Type in the application name you're using)" id="txtAppName" type="text" /></div> 
     <div style="height:4px"></div> 
     <div><textarea name="txtComment" placeholder="Comments..." id="txtComment"></textarea></div> 
     <div style="width:407px; text-align:right;"><input id="submitComment" type="submit" value="Send" /></div> 
    </form> 
1

위의 답변에 표시된대로 각 입력 태그에 name 속성을 추가하십시오. 유 양식이 방법

if(isset($_POST['txtName'] || isset($_POST['txtPass'])) { 
    $txtName = $_POST['txtName']; 
    $txtPass = $_POST['txtPass']; 
    //Everything else here instead require('mail.php'); 
} 

나는 그것을 통해 UR 문제를 해결하고 디버깅에 유하는 데 도움이뿐만 아니라 UR 코드를 확보 희망을 사용하는 경우

또한, 나는 감사하겠습니다.

관련 문제