Created
July 23, 2014 19:51
-
-
Save allgood2386/8c1d4436b52a1b3ac549 to your computer and use it in GitHub Desktop.
my mess
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 | |
/** | |
* @file | |
* add_teach_embed.module | |
* Create a form which we add to the school create/edit forms. Provides a submit hook to invite these users to join. | |
*/ | |
/** | |
* Implements hook_form_alter(). | |
* todo: change weight to something dynamic. IF we reorder anything it will be out of place. | |
*/ | |
function add_teach_embed_form_alter($form, &$form_state, $form_id) { | |
if ($form_id === 'school_node_form') { | |
$form['add_teacher'] = array( | |
'#type' => 'fieldset', | |
'#title' => t('Add Teachers'), | |
'#collapsible' => TRUE, | |
'#collapsed' => TRUE, | |
'#weight' => '12', | |
); | |
$form['add_teacher']['add_teacher_form'] = drupal_get_form('add_teach_embed_form'); | |
$form['actions']['submit']['#submit'][] = 'add_teach_embed_process'; | |
//sdpm($form); | |
} | |
} | |
/** | |
* Implements hook_form(). | |
*/ | |
function add_teach_embed_form($form, &$form_state) { | |
$instruction_text = <<<EOT | |
<h3>Invite teachers to participate</h3><div><p>After your school is credited with its first Heritage | |
Honor Roll legacy sponsorship, your teachers can access online professional development tools, state- and | |
grade-level-specific classroom resources, teacher’s guides, lesson plans and test questions to help them teach more | |
effectively and creatively.</p><p>Please provide an e-mail address for each teacher you want to have access to | |
program resources. Once we receive your list, we will invite each teacher to register for the program. | |
Participation with <sup>®</sup> is voluntary, and there is no cost for teachers to participate. | |
will never sell or share the names and e-mail addresses of participating teachers and their | |
membership is permanent, even if they leave the school for which the user account was created.</p> | |
<p>Also remind your teachers to add to their address book to ensure messages from | |
do not fall into their spam folder.</p></div> | |
EOT; | |
$form_state['storage']['poc_emails'] = isset($form_state['storage']['poc_emails']) ? $form_state['storage']['poc_emails'] : 1; | |
$form = array(); | |
/** | |
$form['#submit'] = array( | |
'add_teach_embed_process', | |
);*/ | |
$form['#tree'] = TRUE; | |
$form['instructions'] = array( | |
'#type' => 'markup', | |
'#markup' => $instruction_text, | |
); | |
$form['poc_emails'] = array( | |
'#type' => 'container', | |
'#tree' => TRUE, | |
'#prefix' => '<div id="teacher-emails">', | |
'#suffix' => '</div>', | |
); | |
if ($form_state['storage']['poc_emails']) { | |
for ($i = 1; $i <= $form_state['storage']['poc_emails']; $i++) { | |
$required = FALSE; | |
if ($i === 1) { | |
$required = TRUE; | |
} | |
$form['poc_emails'][$i] = array( | |
'#type' => 'fieldset', | |
'#tree' => TRUE, | |
); | |
$form['poc_emails'][$i]['poc_email'] = array( | |
'#type' => 'textfield', | |
'#title' => t('E-mail Address'), | |
'#required' => $required, | |
); | |
} | |
} | |
$form['add_one'] = array( | |
'#type' => 'button', | |
'#value' => 'Add Additional Teacher(s)', | |
'#submit' => array(), | |
'#limit_validation_errors' => array(), | |
'#ajax' => array( | |
'callback' => 'add_teach_embed_form_ajax_submit', | |
'wrapper' => 'teacher-emails', | |
'method' => 'replace', | |
'effect' => 'fade', | |
'event' => 'click', | |
'prevent' => 'submit click mousedown', | |
), | |
); | |
$form_state['storage']['poc_emails']++; | |
return $form; | |
} | |
/** | |
* Ajax submit, returns results for the school_views. | |
*/ | |
function add_teach_embed_form_ajax_submit($form, &$form_state) { | |
return $form['poc_emails']; | |
} | |
/** | |
* Submit Handler for the Add Teacher Form. | |
*/ | |
function add_teach_embed_process($form, &$form_state) { | |
sdpm($form); | |
//sdpm($form_state); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment