contact
jeg arbejder i en codelnigter har en Captcha er noget lighed med robot i min contact form MEN den har ikke noget funktion på den måde at den ikke virker jeg kan udføre de andre ting og så sende , men det var ikke noget fejl . det var ikke hensigten med den, den skal bremse maskinelt sendformher er min code
den starter i linje 44-73
så REFRESH i linje 195-213
jeg håber det er en som kan hjælpe mig
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Contact extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Contact_model');
$this->load->library('form_validation');
$this->load->library('session');
// Load the captcha helper
$this->load->helper('captcha');
}
public function index(){
$data = $formData = array();
$contentsdata = array();
if($query = $this->Contact_model->get_contentsdata())
{
$data = $query;
}
$contentsdata = $this->Contact_model->get_contentsdata();
$data = array('contentsdata' => $contentsdata);
// If captcha form is submitted
//if($this->input->post('submit')){
// Load the view
//$this->load->view('contact/index', $data);
/* to her*/
// If contact request is submitted
if($this->input->post('submit')){
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha){
echo 'Captcha code matched.';
}else{
echo 'Captcha code does not match, please try again.';
}
}
// Captcha configuration
$config = array(
'img_path' => 'captcha_images/',
'img_url' => base_url().'captcha_images/',
'font_path' => 'system/fonts/texb.ttf',
'img_width' => '220',
'img_height' => 50,
'word_length' => 8,
'font_size' => 18
);
$captcha = create_captcha($config);
// Unset previous captcha and set new captcha word
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode', $captcha['word']);
// Pass captcha image to view
$data['captchaImg'] = $captcha['image'];
// Get the form data
//if($this->input->post('submit')){
$formData = $this->input->post();
// Form field validation rules
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('adress', 'Adress', 'required');
$this->form_validation->set_rules('city', 'City', 'required');
$this->form_validation->set_rules('zipcode', 'Zipcode', 'required');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
$this->form_validation->set_rules('phone', 'Phone', 'required');
$this->form_validation->set_rules('message', 'Message', 'required');
// indset sikkerhed her
// Validate submitted form data
if($this->form_validation->run() == true){
// Define email data
$mailData = array(
'name' => $formData['name'],
'adress' => $formData['adress'],
'city' => $formData['city'],
'zipcode' => $formData['zipcode'],
'email' => $formData['email'],
'phone' => $formData['phone'],
'message' => $formData['message'],
);
// Send an email to the site admin
@$send = $this->sendEmail($mailData);
// Check email sending status
if($send){
// Unset form data
$formData = array();
$data['status'] = array(
'type' => 'success',
'msg' => 'Din forespørgsel er gået succesfuld igennem.'
);
}else{
$data['status'] = array(
'type' => 'error',
'msg' => 'Some problems occured, please try again.'
);
}
}
// Pass POST data to view
$data['postData'] = $formData;
// Pass the data to view
$theme = 'default';
$this->load->view($theme . '/header',$data);
$this->load->view('contact/index', $data);
$this->load->view($theme . '/footer',$data);
}
private function sendEmail($mailData){
// Load the email library
$this->load->library('email');
// Mail config
$to = 'mail@tordvin.dk';
$from = 'mail@tordvin.dk';
$fromName = 'Tordvin';
$mailSubject = 'Forespørgsel fra: '.$mailData['name'];
//Mail content
$mailContent = '
<table border="1" width="100%" cellpadding="5">
<tr>
<td width="100%"><h2>Forespørgelse fra:</h2></td>
</tr>
</table>
<table border="1" width="100%" cellpadding="5">
<tr>
<td width="30%">Navn:</td><td width="70%">'.$mailData['name'].'</td>
</tr>
<tr>
<td width="30%">Adress:</td><td width="70%">'.$mailData['adress'].'</td>
</tr>
<tr>
<td width="30%">By:</td><td width="70%">'.$mailData['city'].'</td>
</tr>
<tr>
<td width="30%">Post-nr:</td><td width="70%">'.$mailData['zipcode'].'</td>
</tr>
<tr>
<td width="30%">E-mail:</td><td width="70%">'.$mailData['email'].'</td>
</tr>
<tr>
<td width="30%">Tlf-nr:</td><td width="70%">'.$mailData['phone'].'</td>
</tr>
<tr>
<td width="30%">Besked:</td><td width="70%">'.$mailData['message'].'</td>
</tr>
<tr>
<td width="30%">Datapolitik:</td><td width="70%">'.$mailData['checkbox'].'<h4>Jeg accepterer Datapolitik</h4></td>
</tr>
</table>
';
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($to);
$this->email->from($from, $fromName);
$this->email->subject($mailSubject);
$this->email->message($mailContent);
// Send email & return status
return $this->email->send()?true:false;
}
public function refresh(){
// Captcha configuration
$config = array(
'img_path' => 'captcha_images/',
'img_url' => base_url().'captcha_images/',
'font_path' => 'system/fonts/texb.ttf',
'img_width' => '20',
'img_height' => 50,
'word_length' => 8,
'font_size' => 18
);
$captcha = create_captcha($config);
// Unset previous captcha and set new captcha word
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode',$captcha['word']);
// Display captcha image
echo $captcha['image'];
}
}