您已购买主题但我认为联系表格提交中存在错误。主题使用ajax提交联系表格。
联系表单http://192.185.83.133/~lbrisas/TRY/ibrisas/contact.html
当你填写完整的表格并提交我将使用jquery ajax提交表格到contact.php文件,这里是contact.php的代码
码
<?php
spl_autoload_register(function($class_name){
$file_name = str_replace('\\', '/', $class_name);
$file_name = str_replace('_', '/', $file_name);
$file = dirname(__FILE__) . "/lib/$file_name.php";
if(is_file($file)) include $file;
});
use HybridLogic\Validation\Validator;
use HybridLogic\Validation\Rule;
$CONFIG = array(
/* Mail Options */
'mail_send_to' => 'vishalnthoriya@gmail.com',
'mail_contents' => 'mail-content.php',
'mail_failed_msg' => 'An unknown error has occured',
/* Notification Messages */
'form_errors_msg' => '<h4>The following errors were encountered</h4><ul><li>%s</li></ul>',
'form_invalid_msg' => 'The form is invalid',
'form_success_msg' => '<h4>Thank you</h4>Your message has been sent, we\'ll get back to you shortly :)'
);
function createFormMessage( $formdata )
{
global $CONFIG;
ob_start();
extract($formdata);
include $CONFIG['mail_contents'];
return ob_get_clean();
}
function cleanInput($input) {
$search = array(
'@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
);
$output = preg_replace($search, '', $input);
return $output;
}
function sanitize($input) {
if (is_array($input)) {
foreach($input as $var=>$val) {
$output[$var] = sanitize($val);
}
}
else {
if (get_magic_quotes_gpc()) {
$input = stripslashes($input);
}
$input = cleanInput($input);
$output = $input;
}
return $output;
}
$formdata = sanitize( $_POST['ContactForm'] );
$response = array();
$validator = new Validator();
$validator
->set_label('name', 'Name')
->set_label('email', 'Email')
->set_label('subject', 'Subject')
->set_label('comment', 'Comment')
->add_filter('name', 'trim')
->add_filter('email', 'trim')
->add_filter('email', 'strtolower')
->add_filter('subject', 'trim')
->add_rule('name', new Rule\NotEmpty())
->add_rule('email', new Rule\NotEmpty())
->add_rule('email', new Rule\Email())
->add_rule('subject', new Rule\NotEmpty())
->add_rule('comment', new Rule\NotEmpty());
if( $validator->is_valid( $formdata ) )
{
include 'lib/swiftmail/swift_required.php';
$transport = Swift_MailTransport::newInstance();
$mailer = Swift_Mailer::newInstance($transport);
$body = createFormMessage($formdata);
$message = Swift_Message::newInstance();
$message
->setSubject($formdata['subject'])
->setFrom($formdata['email'])
->setTo($CONFIG['mail_send_to'])
->setBody($body, 'text/html');
if( !$mailer->send($message) ) {
$response['success'] = false;
$response['message'] = $CONFIG['mail_failed_msg'];
} else {
$response['success'] = true;
$response['message'] = $CONFIG['form_success_msg'];
}
} else {
$response = array( 'success'=>false, 'message'=>sprintf($CONFIG['form_errors_msg'], implode('</li><li>', $validator->get_errors() ) ) );
}
echo json_encode($response);
?>
这是错误 :解析错误:语法错误,意外T_FUNCTION,期待&#39;)&#39;在第3行的/home/lbrisas/public_html/TRY/ibrisas/php/contact.php
提前致谢
答案 0 :(得分:4)
您需要升级到PHP 5.3才能获得匿名功能支持。
答案 1 :(得分:1)
您需要更改调用函数的方式,因为PHP版本不支持匿名函数:
function stack_2145($class_name)
{
$file_name = str_replace('\\', '/', $class_name);
$file_name = str_replace('_', '/', $file_name);
$file = dirname(__FILE__) . "/lib/$file_name.php";
if(is_file($file)) include $file;
}
spl_autoload_register("stack_2145");
答案 2 :(得分:-2)
而不是使用
spl_autoload_register($class_name) {
// your code
}
尝试使用此
function __autoload($class_name) {
// your code
}