2016-09-06 3 views
0

내 웹 사이트에서 연락 양식을 작성하려고합니다.Wordpress Homepage 양식이 작동하지 않습니다.

저는 PHP 정적 웹 사이트를 위해 이미 저에게 도움이되었던 스크립트를 사용하고 있습니다.

이제는 WordPress 홈페이지에서 구현하려고하는데 작동하지 않는 것 같습니다.

제출할 때 블로그 페이지 또는 "홈페이지"로 리디렉션되지만 대신 블로그 항목이 사용됩니다.

제출시 에코 유효성 검사를 받아야하지만 실제로 발생하지는 않습니다.

나는 action = "", action = "#", PHP_SELF, action = "/", action = "index", action = "index.php"로 시도했지만 아무도 작동하지 않습니다.

<form method="post" action=""> 

       <p><?php echo $output; ?></p> 

       <label for="name">Your beautiful name goes here</label> 
       <input type="text" name="name" id="name"> 

       <label for="mail">I need your email to write you back, type it below</label> 
       <input type="email" name="mail" id="mail"> 

       <label for="dropdown">Are you looking for help in something specific or just wanted to say HI?</label> 
       <select name="dropdown" id="dropdown"> 
        <option>Just wanted to say Hi!</option> 
        <option>I need help with my brand</option> 
        <option>I want to launch a website</option> 
        <option>Other</option> 
       </select> 

       <label for="else">Is there something else you want to tell me?</label> 
       <textarea name="else" id="else"> 

       </textarea> 

       <button class="btn btn-red" name="send" type="submit">SEND</button> 

      </form> 
+0

PHP 코드는 어떤 파일에 있습니까? –

+0

아마 워드 프레스 모드 재 작성 규칙을 재생합니다. 왜 당신은 Wordpress에서 이것을하지 않습니까? – nogad

+0

구문 오류가 있는지 확인 했습니까? 한 줄에'; '이 보이지 않는다. –

답변

0

양식 행동에 정규화 된 URL을 사용해보십시오 즉, www.yourdomain.com/form-processor-

<?php 

$send = $_POST['send'] 

// Address to get the mails 
$EmailTo = "[email protected]"; 


// Form input fields 
$name = $_POST['name']; 
$email = $_POST['email']; 

$subject = explode('|', $_POST['dropdown']);; 

$message = $_POST['message']; 

if (isset($send)) { 

    if (empty($email)) { 
     $output = 'Hey, I need your email to reply'; 
    } 

    elseif (empty($name)) { 
     $output = 'Ups, you forgot your name'; 
    } 

    else{ 
     mail("[email protected]", $subject, $message, "From: $email\n"); 
     $output = 'Thanks, your submission has been sent'; 
    } 
} 

?> 

그리고 내 HTML 양식 :

내 코드입니다 script.php.

부수적으로 일반적으로 사용자가 양식을 제출하지 않아야합니다. 이는 사용자가 브라우저의 새로 고침 버튼을 사용하여 양식 데이터를 다시 제출할 수 있도록하기 때문에 나쁜 "양식"입니다. 또한 프리젠 테이션 레이어에 로직을 삽입합니다. Post-Redirect-Get 또는 PRG 패턴을 살펴보십시오.

+0

조언 주셔서 감사합니다. 나는 그것을 할 거 야. – Ferrius

+0

나는 이미 정확한 URL을 넣으려고했으나 제대로 작동하지 않았다. – Ferrius

+0

무엇이 작동하지 않습니까? 양식 처리 스크립트? 나는 당신이 wordpress에서 간단한 mail() 함수를 사용할 수 있다고 생각하지 않는다. 양식이 대상 작업 위치에 데이터를 제출하지 않습니까? WordPress에 wp_mail() 함수가 내장되어 있습니다. 양식 처리 스크립트를 간단한 출력으로 바꾸어 양식이 제출되고 있는지 확인하십시오. 그런 다음 스크립트 문제를 해결하십시오. 그대로 서면 이메일이 정확하다면 스크립트가 작동한다는 것을 알 수 있습니까? 양식 제출과 전자 메일이 실행되는 사이에 많은 문제가 발생할 수 있습니다. – joeDaigle

0

몇 가지 조사를 한 후에 양식 작업을 실행하는 가장 좋은 방법은 양식 HTML 및 처리를 WP 플러그인으로 변환하는 것입니다.

당신은

<?php 

/* 
    Plugin Name: Contact Form Plugin 
    Plugin URI: http://ferrius.co 
    Description: Simple non-bloated WordPress Contact Form 
    Version: 1.0 
    Author: Sebastian Ferreira 
    Author URI: http://ferrius.co 
*/ 


function html_form_code() { 

    echo '<form action="' . esc_url($_SERVER['REQUEST_URI']) . '" method="post">'; 
    echo '<br>'; 

    echo '<label for="cf-name">Your beautiful name goes here</label>'; 
    echo '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . (isset($_POST["cf-name"]) ? esc_attr($_POST["cf-name"]) : '') . '"/>'; 

    echo '<label for="cf-email">I need your email to write you back, type it below</label>'; 
    echo '<input type="email" name="cf-email" value="' . (isset($_POST["cf-email"]) ? esc_attr($_POST["cf-email"]) : '') . '"/>'; 

    echo '<label for="cf-subject">Are you looking for help in something specific or just wanted to say HI?</label>'; 
    echo '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value="' . (isset($_POST["cf-subject"]) ? esc_attr($_POST["cf-subject"]) : '') . '" />'; 

    echo '<label for="cf-message">Is there something else you want to tell me?</label>'; 
    echo '<textarea name="cf-message">' . (isset($_POST["cf-message"]) ? esc_attr($_POST["cf-message"]) : '') . '</textarea>'; 

    echo '<button class="btn btn-red" type="submit" name="cf-submitted" value="SEND"/>SEND</button>'; 
    echo '</form>'; 

} 

function deliver_mail() { 

    // if the submit button is clicked, send the email 
    if (isset($_POST['cf-submitted'])) { 

     // sanitize form values 
     $name = sanitize_text_field($_POST["cf-name"]); 
     $email = sanitize_email($_POST["cf-email"]); 
     $subject = sanitize_text_field($_POST["cf-subject"]); 
     $message = esc_textarea($_POST["cf-message"]); 

     // get the blog administrator's email address 
     $to = "[email protected]"; 

     $headers = "From: $name <$email>" . "\r\n"; 

     // If email has been process for sending, display a success message 
     if (wp_mail($to, $subject, $message, $headers)) { 
      echo '<div>'; 
      echo '<p>Thanks for contacting me, expect a response soon.</p>'; 
      echo '</div>'; 
     } else { 
      echo 'An unexpected error occurred'; 
     } 
    } 
} 

function cf_shortcode() { 
    ob_start(); 
    deliver_mail(); 
    html_form_code(); 

    return ob_get_clean(); 
} 

add_shortcode('ferrius_contact_form', 'cf_shortcode'); 

?> 

아래의 코드에서 볼 누군가를위한 유용한 희망 할 수 있습니다.

관련 문제