Skip to content

Instantly share code, notes, and snippets.

@xtfer
Created August 5, 2014 03:11
Show Gist options
  • Save xtfer/2063d158deafce34cc06 to your computer and use it in GitHub Desktop.
Save xtfer/2063d158deafce34cc06 to your computer and use it in GitHub Desktop.
Ghost: FormController example
<?php
/**
* @file
* Contains a FormExample
*
* @license GPL v2 http://www.fsf.org/licensing/licenses/gpl.html
* @author Chris Skene chris at previousnext dot com dot au
* @copyright Copyright(c) 2014 Previous Next Pty Ltd
*/
namespace Drupal\ghost_examples\Form;
use Drupal\ghost\Form\BaseForm;
use Drupal\ghost\Form\FormInterface;
/**
* Class ExampleForm
* @package Drupal\ghost_examples\Form
*/
class ExampleForm extends BaseForm implements FormInterface {
/**
* {@inheritdoc}
*/
public function buildForm(array &$form, array &$form_state) {
$form['my_field'] = array(
'#type' => 'textfield',
'#title' => t('My field'),
'#default_value' => t('Some default value'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
// Do any validation...
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
// Do something with the form here...
drupal_set_message('Save complete!');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment