Created
September 20, 2011 19:21
-
-
Save suderman/1230049 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 'n_model.php'; | |
class Contact extends NModel { | |
function __construct() { | |
$this->__table = 'contact'; | |
$this->form_required_fields = array('first_name','last_name','email'); | |
$this->form_elements['address'] = array('textarea', 'address', 'Address', array('rows'=>1,'cols'=>50)); | |
$this->form_elements['zip_postal_code'] = array('text', 'zip_postal_code', 'Zip/Postal Code'); | |
$this->form_elements['province'] = array('text', 'province', 'State/Province'); | |
$this->form_elements['topic'] = array('select', 'topic', 'Please choose a topic', array( | |
'Domestic Manufacturing'=>'Domestic Manufacturing', | |
'International Coating & Equipment'=>'International Coating & Equipment', | |
'Investor Relations'=>'Investor Relations')); | |
$this->form_elements['message'] = array('textarea', 'message', 'Your messages/comments', array('rows'=>3,'cols'=>50)); | |
parent::__construct(); | |
} | |
} | |
?> |
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