The normal contact action is below...(it works, but just included it to be complete - if you do look through it and have improvements, they are welcome)
Code: Select all
public function contactAction()
{
# get form
$contactForm = $this->_getContactForm();
# if there is a post
if ($this->getRequest()->isPost()) {
$formData = $this->_request->getPost(); // get post data
$contactForm->populate($formData); // populate form with data
# check to see if from a quick form, if so do not display errors just yet
if (empty($formData['quick']))
{
# valid post and display message to user accordingly
if (!$contactForm->isValid($_POST))
{
$this->view->error = "Please fill in all required information marked in red"; // message to the user
# display form with filled in data
$this->view->contactForm = $contactForm;
}
else
{
$this->view->error = "Message sent"; // message to the user
# get info from global.ini
$contact = Zend_Registry::getInstance()->global->contact;
$emailTo = $contact->email;
$emailName = $contact->name;
# send email
$mail = new Zend_Mail();
$mail->setFrom($formData['email'], $formData['name']);
$mail->addTo($emailTo, $emailName);
$mail->setSubject('JS: '.$formData['subject']);
$mail->setBodyText($formData['info']);
$mail->send();
}
}
else
{
# display form with filled in data
$this->view->contactForm = $contactForm;
}
}
else
{
# display form empty
$this->view->contactForm = $contactForm;
}
}Code: Select all
public function contactajaxAction()
{
# disable display
$this->_helper->layout->disableLayout();
# contact page
$this->contactAction();
}Code: Select all
// AJAX
$.fn.ajax = function() {
$('.ajax').ajaxStart(function() {
$(this).html('<img src="/images/loading.gif" alt="ajax loading" />');
});
$('.ajax').ajaxStop(function() {
$(this).html('');
});
}
// CONTACT FORM
$.fn.contactForm = function() {
$('form#contact input#submit').click( function(event)
{
event.preventDefault();
// get form data
var name = $('form#contact input#name').val();
var email = $('form#contact input#email').val();
var subject = $('form#contact select#subject').val();
var info = $('form#contact textarea#info').val();
var spamcode_id = $('form#contact input#spamcode-id').val();
var spamcode_code = $('form#contact input#spamcode-input').val();
// send form data & get return data
$('div#content').load('/index/contactajax/',
{ 'name' :name,
'email' :email,
'subject' :subject,
'info' :info,
'spamcode_id' :spamcode_id,
'spamcode_code' :spamcode_code },
function() {
$.fn.contactForm();
}
);
});
}
$.fn.contactForm();
$.fn.ajax();