[eluser]elaniobro[/eluser]
I've gotten pretty far with this. I got the page making the ajax call.
Prior to putting ajax in, sending an e-mail was no problem. Once I put it in, it no longer sends. It will still validate, however if you pass the validation, it will just load the success view and not send an e-mail.
controller:
Code: <?php
class Email extends Controller
{
function Email()
{
parent::Controller();
}
function index()
{
$this->load->view('email_view');
}
function send()
{
$this->load->library('form_validation');
//field name, error message, validation rules
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email');
$this->form_validation->set_rules('fullName', 'full name', 'trim|required|min_length[5]');
if($this->form_validation->run() == FALSE)
{
$this->load->view('email_view');
}else{
//validaiton has past, send e-mail
$fullName = $this->input->post('fullName');
$email = $this->input->post('email');
$subject = $this->input->post('subject');
$message = $this->input->post('message');
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'smtp.example.com',
'smtp_port' => 143,
'smtp_user' => '[email protected]',
'smtp_pass' => 'start123'
);
$this->load->library('email');
$this->email->from($email, $fullName);
$this->email->to('[email protected]');
$this->email->subject($subject);
$this->email->message($message);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
if($this->input->post('ajax'))
{
$this->load->view('emailSucess_view');
}else{
$this->load->view('email_view');
}
}
}
}
?>
[eluser]elaniobro[/eluser]
view:
Code: <div class="popup-container" id="contact-container">
<div class="watermark">
<?=img(array('src'=>'img/footer/trybuch_contact_a.png','alt'=>'contact'));?>
</div>
<div class="close">
<?= anchor('',
img(array(
'src'=>'img/nav/nav_close_a.gif',
'id'=>'contactBack',
'border'=>'0',
'alt'=>'Close'
)
),
array(
'onmouseover'=>'contactBack'.'.src='."'".base_url().'img/nav/nav_close_b.gif'."'".';'.'"',
'onmouseout'=>'contactBack'.'.src='."'".base_url().'img/nav/nav_close_a.gif'."'".';'.'"'
)
);
?>
</div>
<div class="clear"></div>
<div id="contact-form">
<div class="title">
<?= img(array('src'=>'img/footer/contact/trybuch_title_contact.gif','alt'=>'Contact Form'));?>
</div>
<?= form_open('email/send');?>
<p><input><label class="contact-label">email</label></p>
<p><input><label class="contact-label">full name</label></p>
<p><input><label class="contact-label">subject</label></p>
<p><textarea>So tell me what is on your mind....</textarea></p>
<?= form_submit('submit','Send','id="submit"');?>
<?= form_close();?>
<?= validation_errors('<p class="contact-error">');?>
</div>
</div>
[removed]
$('#submit').click(function()
{
var contact_data =
{
fullName: $('#fullName').val(),
email: $('#email').val(),
subject: $('#subject').val(),
message: $('#message').val(),
ajax: '1'
};
$.ajax({
url: "<?php echo site_url('email/send');?>",
type: 'POST',
data: contact_data,
success: function(msg){
$('#contact-container').html(msg);
}
});
return false;
});
[removed]
[eluser]Kamarg[/eluser]
You seem to be missing $this->email->send() within your send function.
[eluser]elaniobro[/eluser]
[quote author="Kamarg" date="1268859577"]You seem to be missing $this->email->send() within your send function.[/quote]
oh man, thanks for that.. I guess I deleted that line accidentally and did not notice when I started implementing the ajax
It is usually the most obvious. Thanks Kamarg!
Cheers!
|