2011-11-22 2 views
0

나는이 학교 프로젝트에 대한 작업을하고 있는데 내 양식을보기 및 기능에 제대로 연결하는 데 문제가 있습니다.HTML 파일 - 간단한 양식 및 유효성 검사기의 PHP

This is my School Project

문제/질문 (들) :
1) 나는 심지어이 PHP "내부"HTML 문서를 사용할 수 있습니까? (The Demo I am Trying to Follow)

이 (AN HTML의 DOC IN) 내 FORM 항목 입니다 :

<div id="formWrap"> 
     <div id="form"> 
      <form action="contact.php" method="post" id="comments_form"> 
     <div class="row"> 
     <div class="label">Your Name</div> 
     <div class="input"> 
      <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /> 

      <?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?> 

     </div> <!-- end input class --> 
     <div class="context">e.g. John Smith or Jane Doe</div><!-- end context class --> 
    </div><!-- end row class --> 

    <div class="row"> 
     <div class="label">Your Email Address</div> 
     <div class="input"> 
      <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /> 

      <?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?> 

     </div> <!-- end input class --> 
     <div class="context">We will not share your email address with anyone.</div><!-- end context class --> 
    </div><!-- end row class --> 

    <div class="row"> 
     <div class="label">Tell Us All About It!</div> 
     <div class="input"> 
      <textarea id="comment" name="comment" class="mess"> 
       <?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?> 
      </textarea> 

      <?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?> 

     </div> <!-- end input class --> 
    </div><!-- end row class --> 

    <div class="submit"> 
     <input type="submit" id="submit" name="submit" value="Send Message" /> 
     </form> 
     <?php else: ?> 
      <p>Thank you for your Message!</p> 
     <?php endif; ?> 

    </div><!-- end submit class --> 
    </div><!-- end form --> 

     <?php if($form_complete === FALSE): ?> 

    </div><!-- end form wrap --> 
+0

PHP가 웹 사이트를 호스팅하는 서버에 설치되어 있습니까? 그렇지 않으면 PHP가 작동하지 않습니다. – sicks

답변

2

PHP 블록 (<?php ?>)가 PHP 파서/통역에 의해 처리되어야합니다. 이것은 엔진이 읽어야 할 파일과 무시할 파일을 알아야한다는 것을 의미합니다. 이 파일의 이름이 index.html이라면 PHP 인터프리터는이를 무시할 것입니다 (기본적으로 이것을 변경할 수는 있지만 일반적으로 또는 권장되는 것은 아닙니다).

정확하게 PHP 파일 (그러나 <?php ?> 블록 외부)에 HTML을 넣을 수는 있지만 PHP를 HTML 파일 안에 넣을 수는 없습니다.

파일 이름이 index.html 인 경우 이름을 index.php으로 변경하고 코드 작동 여부를 확인하십시오.

+0

알 겠어. 나는 이것을 시도하고 다시하고 당신과 함께 돌아올 것입니다. 감사. 또한, 단지 명확하게 - html5는 index.php 시나리오에서 잘 작동합니까? – Varazi

+0

HTML이 PHP 블록 외부에 포함되어 있다면, 예, 인터프리터는 PHP를 실행하고 영향을주지 않고 HTML을 출력합니다. – rockerest

+0

예 index.html을 index.php로 변경하십시오. –

1

html 확장자를 유지하려면 서버 구성을 HTML 개의 파일로 구문 분석하여 PHP으로 구문 분석 할 수 있습니다.

설치 PHPApache 서버 예를 들어, 당신은 당신의 웹 사이트 디렉토리에 .htaccess 파일을 생성하고 AddType 지시문을 사용할 수 있습니다

AddType application/x-httpd-php .html 

를 또는 대안 당신은 php.ini 파일을 편집 할 수 있습니다.

0

PHP를 설치하지 않았거나 웹 서버가 .html 개의 파일을 PHP에 전달하도록 구성되지 않았습니다. this page이라는 PHP 파일이 설치되어 있다고 판단하여 index.html에서 index.php으로 파일의 이름을 바꾸거나 Apache/웹 서버를 다시 구성하면됩니다.

+0

ummm, http://glustik.com/index.php가 존재하지 않습니다. buddy –

+0

@PranavHosangadi - 음,이 답변을 게시 할 때 "buddy"가 나타납니다. – nickb