【发布时间】:2014-02-28 18:33:53
【问题描述】:
我不断看到 if 语句在域 http://bambooflooringcapetown.net/recap.php 上显示为文本
你可以自己看看。
我正在尝试在我的表单中实施 Securimage,但遇到了麻烦。
我正在使用的验证码: http://www.phpcaptcha.org/documentation/quickstart-guide/
当前代码:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
?>
<div>
<?php
require_once 'securimage/securimage.php';
// Code Validation
$image = new Securimage();
if ($image->check($_POST['captcha_code']) == true) {
echo "Correct!";
} else {
echo "Sorry, wrong code.";
}
require_once 'securimage/securimage.php';
echo Securimage::getCaptchaHtml();
?>
</div>
<style>
#newheadform
{
position: relative;
top: -15px;
left: 700px;
width: 280px;
height: 361px;
border: 1px solid #<?php echo $Config['bodyFontColour']; ?>;
background-color: #<?php echo $Config['bodyColour']; ?>;
color: #<?php echo $Config['bodyFontColour']; ?>;
opacity: 0.85;
padding: 10px;
z-index: 100;
font-family: sans-serif;
}
#newheadform input[type=text], #newheadform textarea
{
border: 1px solid #000;
width: 96%;
}
</style>
<!-- NEW ENQUIRY FORM START -->
<form method="post" action="">
<table id="newheadform" cellpadding="5" cellspacing="0">
<tr><th colspan="2" align="center"><font size="5">Email us now</font></th></tr>
<tr><td>Name*:</td><td><input type="text" name="name"/></td></tr>
<tr><td>Phone*:</td><td><input type="text" name="number"/></td></tr>
<tr><td>Email*:</td><td><input type="text" name="email"/></td></tr>
<tr><td colspan="2">Message:</td></tr>
<tr><td colspan="2"><textarea name="message" style="height: 50px;"></textarea></td></tr>
<tr><td colspan="2" align="center">
<input type="text" name="captcha_code" size="10" maxlength="6" />
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Different Image</a>
<?php if(isset($_POST['number']))
{
if(empty($_POST['name']) || empty($_POST['number']) || empty($_POST['email']))
echo '<font color="red" size="1"><b>* These fields are compulsory</b></font><br/><br/>';
else
{
$headers='From: '.$_POST['email']."rn";
$headers.='Reply-To: '.$_POST['email']."rn";
$headers.='X-Mailer: PHP/'.phpversion();
$body='You received a contact request from '.$_POST['name'].' ('.$_POST['email'].') on your site '.$domainname."rn";
$body.='Contact number: '.$_POST['number']."rnrn";
if(!empty($_POST['message'])) $body.=$_POST['message'];
if(mail($_SESSION['contact3'],'New Enquiry from '.$domainname,$body,$headers))
echo '<font color="green"><b>Your email has been sent</b></font><br/>';
}
}
?>
<img id="captcha" src="securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="button" name="send" value="Send"/></td></tr>
</table>
</form>
<!-- NEW ENQUIRY FORM END -->
没有验证码的原始代码
<!-- NEW ENQUIRY FORM START -->
<style>
#newheadform
{
position: relative;
top: -15px;
left: 700px;
width: 280px;
height: 361px;
border: 1px solid #<?php echo $Config['bodyFontColour']; ?>;
background-color: #<?php echo $Config['bodyColour']; ?>;
color: #<?php echo $Config['bodyFontColour']; ?>;
opacity: 0.85;
padding: 10px;
z-index: 100;
font-family: sans-serif;
}
#newheadform input[type=text], #newheadform textarea
{
border: 1px solid #000;
width: 96%;
}
</style>
<form method="post" name="newheadformform">
<table id="newheadform" cellpadding="5" cellspacing="0">
<tr><th colspan="2" align="center"><font size="5">Email us now</font></th></tr>
<tr><td>Name*:</td><td><input type="text" name="name"/></td></tr>
<tr><td>Phone*:</td><td><input type="text" name="number"/></td></tr>
<tr><td>Email*:</td><td><input type="text" name="email"/></td></tr>
<tr><td colspan="2">Message:</td></tr>
<tr><td colspan="2"><textarea name="message" style="height: 50px;"></textarea></td></tr>
<tr><td colspan="2" align="center">
<?php if(isset($_POST['number']))
{
if(empty($_POST['name']) || empty($_POST['number']) || empty($_POST['email']))
echo '<font color="red" size="1"><b>* These fields are compulsory</b></font><br/><br/>';
else
{
$headers='From: '.$_POST['email']."rn";
$headers.='Reply-To: '.$_POST['email']."rn";
$headers.='X-Mailer: PHP/'.phpversion();
$body='You received a contact request from '.$_POST['name'].' ('.$_POST['email'].') on your site '.$domainname."rn";
$body.='Contact number: '.$_POST['number']."rnrn";
if(!empty($_POST['message'])) $body.=$_POST['message'];
if(mail($_SESSION['contact3'],'New Enquiry from '.$domainname,$body,$headers))
echo '<font color="green"><b>Your email has been sent</b></font><br/>';
}
}
else echo '<font size="1">* Compulsory</font><br/><br/>'; ?>
Calculate*: <span id="num1"></span> + <span id="num2"></span> <input type="number" name="calculate" placeholder="" /><br><br>
<input type="button" name="send" value="Send"/></td></tr>
</table>
</form>
<script type="text/javascript">
$(document).ready(function(e) {
var number1 = Math.floor(Math.random()*12)+1;
var number2 = Math.floor(Math.random()*12)+1;
$('#num1').append(number1);
$('#num2').append(number2);
$('input[name=send]').click(function(){
var total = number1 + number2;
var answer = $('input[name=calculate]').val();
if(total !== parseInt(answer)){
alert("Please enter the correct calculation to send your enquiry.");
} else {
document.newheadformform.submit();
return false;
}
});
});
</script>
<!-- NEW ENQUIRY FORM END -->
【问题讨论】:
-
旁注:您正在将 CSS/HTML 与 PHP 混合。把它们分开。
-
你的 PHP 必须被包裹在
<?php标签中。但就像@Fred-ii- 说如果 PHP 在另一个文件中会更好 -
如何拆分它们?因为这一切都来自 index.php
-
该死的,我每次都在 中包装任何新的东西,它会破坏整个页面
-
看来我在表单验证和一般如何使用验证码和表单发送方面遇到了问题
标签: php