WP联系表格.php

时间:2015-07-07 11:12:21

标签: php wordpress forms

您好我在我的WP页面中创建了一个php表单,但是当我尝试提交信息时,我收到错误“找不到对象”。 php和html都在同一个文件页面上 - contact-us.php 我很感激答案

<?php
if (isset($_POST['submit'])){
$to='########################';
$subject = 'nova mensagem';

$name = $_POST['f_name'];
$company = $_POST['f_company'];
$role = $_POST['f_role'];
$email = $_POST['f_email'];
$subject = $_POST['f_subject'];
$message = $_POST['f_message'];
$human = intval($_POST['f_human']);

$from = 'form de comentários'; 

$body = "De: $name\n Empresa: $company\n Cargo: $role\n Assunto: $subject\n Message:\n $message";

if (isset($_POST['f_name'])) {
  $errName = 'Por favor indique o seu nome';}

if (!$_POST['f_email'] || !filter_var($_POST['f_email'], FILTER_VALIDATE_EMAIL)) {
  $errEmail = 'Indique um email valido';}

if (!$_POST['f_subject']) {
  $errSubject = 'Indique um assunto valido';}

if (!$_POST['f_message']){
     $errMessage = 'Indiquem um comentário';}

if ($human !== 5) {
     $errHuman = 'A sua conta está errada :)';}

if (!$errName && !$errEmail && !$errMessage && !$errHuman) {
    if (mail ($to, $subject, $from)) {
         $result='<div class="alert alert-success">Obrigado!</div>';
    }           
    else {
        $result='<div class="alert alert-danger">Ocorreu um erro tente mais tarde</div>';
    }
}
  }?>

表格

<form class='form-horizontal' role='form' method='POST' action='page-contact-us.php'>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_name" name="f_name" placeholder="Nome" value="">
        <?php if (!empty($errName)) { ?>
        <?php echo "<p class='text-danger'>$errName</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_company" name="f_company" placeholder="Empresa" value="">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_role" name="f_role" placeholder="Cargo" value="">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="email" class="form-control" id="f_email" name="f_email" placeholder="exemplo@dominio.com" value="">
        <?php if(!empty($errEmail)) { ?>
        <?php echo "<p class='text-danger'>$errEmail</p>";?>
        <?php } ?>
    </div>
</div>

 <div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_subject" name="f_Subject" placeholder="Assunto" value="">
        <?php if(!empty($errSubject)) { ?>
        <?php echo "<p class='text-danger'>$errSubject</p>";?>
        <?php } ?>
    </div>
</div>

<div class="form-group">
    <div class="col-sm-10">
        <textarea class="form-control" rows="4" name="f_message" placeholder="Insira um comentario"></textarea>
        <?php if(!empty($errMessage)) { ?>
        <?php echo "<p class='text-danger'>$errMessage</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_human" name="f_human" placeholder="Sua resposta">
        <?php if(!empty($errHuman)) { ?>
        <?php echo "<p class='text-danger'>$errHuman</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
        <input id="submit" name="submit" type="submit" value="Enviar" class="btn btn-primary">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
      <?php if (!empty($result)) { ?>
      <?php echo $result; ?>    
      <?php } ?>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

将代码更改为

<form class='form-horizontal' role='form' method='POST' action=''>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_name" name="f_name" placeholder="Nome" value="">
        <?php if (!empty($errName)) { ?>
        <?php echo "<p class='text-danger'>$errName</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_company" name="f_company" placeholder="Empresa" value="">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_role" name="f_role" placeholder="Cargo" value="">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10">
        <input type="email" class="form-control" id="f_email" name="f_email" placeholder="exemplo@dominio.com" value="">
        <?php if(!empty($errEmail)) { ?>
        <?php echo "<p class='text-danger'>$errEmail</p>";?>
        <?php } ?>
    </div>
</div>

 <div class="form-group">
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_subject" name="f_Subject" placeholder="Assunto" value="">
        <?php if(!empty($errSubject)) { ?>
        <?php echo "<p class='text-danger'>$errSubject</p>";?>
        <?php } ?>
    </div>
</div>

<div class="form-group">
    <div class="col-sm-10">
        <textarea class="form-control" rows="4" name="f_message" placeholder="Insira um comentario"></textarea>
        <?php if(!empty($errMessage)) { ?>
        <?php echo "<p class='text-danger'>$errMessage</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <label for="human" class="col-sm-2 control-label">2 + 3 = ?</label>
    <div class="col-sm-10">
        <input type="text" class="form-control" id="f_human" name="f_human" placeholder="Sua resposta">
        <?php if(!empty($errHuman)) { ?>
        <?php echo "<p class='text-danger'>$errHuman</p>";?>
        <?php } ?>
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
        <input id="submit" name="submit" type="submit" value="Enviar" class="btn btn-primary">
    </div>
</div>
<div class="form-group">
    <div class="col-sm-10 col-sm-offset-2">
      <?php if (!empty($result)) { ?>
      <?php echo $result; ?>    
      <?php } ?>
    </div>
</div>