Created
September 20, 2011 19:20
-
-
Save suderman/1230048 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'app/controllers/asset_controller.php'; | |
class ContactController extends AssetController { | |
function __construct() { | |
$this->name = 'contact'; | |
$this->versioning = true; | |
$this->base_view_dir = ROOT_DIR; | |
parent::__construct(); | |
} | |
function contactForm() { | |
$email_to = '[email protected]'; | |
$model = NModel::factory($this->name); | |
$cform = &new ControllerForm($this, $model); | |
$form = &$cform->getForm(); | |
// Remove some default elements | |
$form->removeElement('cms_headline'); | |
$form->removeElement('__submit_draft__'); | |
$form->removeElement('__header__'); | |
// Change submit button's value from 'Save' to 'Submit | |
$form->removeElement('__submit__'); | |
$form->addElement('submit', '__submit__', 'Submit'); | |
// If post submitted and valid data | |
if ($form->validate()) { | |
$vals = $form->getSubmitValues(); | |
$msg = $form->getEmailMsg($vals); | |
$vals['cms_headline'] = $vals['first_name'].' '.$vals['last_name']. ' - ' .$vals['email']; | |
$id = $cform->processForm($vals); | |
if (!$model->cms_created) { $model->cms_created = $model->now(); } | |
$model->cms_modified = $model->now(); | |
$model->cms_modified_by_user = 1; | |
$model->update(); | |
// Send an email. | |
$headers = 'From:' . $vals['email']; | |
mail($email_to, 'Email Subject Line', $msg, $headers); | |
print '<p>Your form has been submitted!</p>'; | |
// Just render the form | |
} else { | |
print $form->display(); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment