【发布时间】:2014-01-21 05:11:36
【问题描述】:
我有一个我设计的 wordpress 主题,我在地址上有一个联系表 -
www.[website_name].com/contact
我有一个表单定义,上面写着 -
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
以及我使用
确定 post 方法的方式if ($_SERVER["REQUEST_METHOD"] == "POST"){ // followed by my code for the form
但是,当我使用这种语法提交表单时,我会被重定向到
www.[website_name].com/index.php
通过谷歌搜索,我在几个地方找到了尝试
<form method="post" action="<?php echo get_permalink(); ?>">
我被重定向到http://[website_name].com/contact/
但在这种情况下也没有提交表格。
我也试过绝对网址 -
www.[website_name].com/wp-content/themes/[theme-name]/contact.php
www.[website_name].com/contact.php
www.[website_name].com/contact
但一切都是徒劳的,有人可以帮我解决这个问题吗? 抱歉,我以前使用过 get_permalink,但即使是永久链接也不适合我,这里是我正在使用的完整代码 -
<?php
/*
Template Name: Contact
*/
?>
<?php
$errormsg="";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
if (!empty($_POST["name"]))
$name=$_POST["name"];
if (!empty($_POST["number"]))
$number=$_POST["number"];
if (!empty($_POST["address"]))
$address=$_POST["address"];
if (!empty($_POST["purpose"]))
$purpose=$_POST["purpose"];
require_once('PHPMailer_5.2.4/class.phpmailer.php');
$mail = new PHPMailer();
$body="test body2";
$mail->IsSMTP();
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = "harshitladdha93@gmail.com"; // GMAIL username
$mail->Password = "[password]"; // GMAIL password
$mail->SetFrom("harshitladdha93@gmail.com", 'Harshit Laddha');
$mail->AddReplyTo("harshitladdha93@gmail.com","First Last");
$mail->Subject = "subject";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "maniyogi764.com@gmail.com";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
$errormsg="mail sent";
} else {
$errormsg="some error occurred, please contact webmaster at contact@exoticalstudio.com.";echo $mail->ErrorInfo;
}
}
?>
<?php get_header(); ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url');?>/css/contact/css/style.css" />
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url');?>/css/contact/css/animate-custom.css" />
<link type="text/css" rel="stylesheet" href="<?php bloginfo('template_url');?>/css/contact/css/styles/form.css?v3.1.1082"/>
<style type="text/css">
.form-label{
width:150px !important;
}
.form-label-left{
width:150px !important;
}
.form-line{
padding-top:12px;
padding-bottom:12px;
}
.form-label-right{
width:150px !important;
}
.form-all{
width:650px;
color:#FFFFFF !important;
font-family:'Verdana';
font-size:12px;
}
.form-radio-item label, .form-checkbox-item label, .form-grading-label, .form-header{
color:#FFFFFF;
}
</style>
<div class="content" style="top:0px" >
<div class="designs" style="color:#646464;">
<div id="wrapper" style="width:60%;margin-left:25%;text-align:left;">
<div id="login" class="animate form">
<form method="post" action="<?php the_permalink(); ?>">
<h1><?php if (!empty($_POST["name"])) echo $errormsg; else echo "Connect with us!"?></h1>
<div class="form-all">
<ul class="form-section">
<li class="form-line">
<label class="form-label-left" for="name">
Full Name<span class="form-required">*</span>
</label>
<div class="form-input"><span class="form-sub-label-container"><input class="form-textbox validate[required]" type="text" size="30" name="name" id="name" /></span>
</div>
</li>
<li class="form-line">
<label class="form-label-left" for="number"> Phone Number </label>
<div class="form-input"><span class="form-sub-label-container"><input class="form-textbox" type="tel" name="number" id="number" size="10">
</span>
</div>
</li>
<li class="form-line">
<label class="form-label-left" id="label_7" for="address">
Address
</label>
<div class="form-input">
<input id="address" class="form-textarea " name="address"/>
</div>
</li>
<li class="form-line">
<label class="form-label-left" for="textarea">
Purpose<span class="form-required">*</span>
</label>
<div class="form-input">
<textarea id="purpose" class="form-textarea validate[required]" name="purpose" cols="35" rows="6"></textarea>
</div>
</li>
<li class="form-line">
<div class="form-input-wide">
<div style="margin-left:156px" class="form-buttons-wrapper">
<button id="submit" type="submit" class="form-submit-button">
Submit
</button>
</div>
</div>
</li>
<li style="display:none">
Should be Empty:
<input type="text" name="website" value="" />
</li>
</ul>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="<?php bloginfo('template_url');?>/js/cbpTooltipMenu.min.js"></script>
<script>
var menu = new cbpTooltipMenu( document.getElementById( 'cbp-tm-menu' ) );
</script>
<?php get_footer(); ?>
【问题讨论】: