hi i have purchased theme but i think there is bug in contact form submission. theme use ajax to submit contact form.
link of contact form http://192.185.83.133/~lbrisas/TRY/ibrisas/contact.html
when you fill complete form and submit i will submit form using jquery ajax to contact.php file and here is code for the contact.php
code
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' => 'The following errors were encountered
- %s
',
'form_invalid_msg' => 'The form is invalid',
'form_success_msg' => 'Thank you
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(
'@@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@@siU', // Strip style tags properly
'@@' // 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('', $validator->get_errors() ) ) );
}
echo json_encode($response);
?>
here is error
:Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /home/lbrisas/public_html/TRY/ibrisas/php/contact.php on line 3
thanks in advance
Answer
You need to change the way of calling function since anonymous functions are not supported in your PHP version:
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");
No comments:
Post a Comment