Last active
August 29, 2015 14:04
-
-
Save AllieRays/e6e8d5a3c5e46b5780b2 to your computer and use it in GitHub Desktop.
Two different hook form alter
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
//example one | |
//using a session key profile to hide elements when credentials are already given from a different login account | |
function vod_oauth_medscape_user_insert(&$edit, $account, $category) { | |
// load frontend functions | |
module_load_include('inc', 'vod_oauth_medscape', 'vod_oauth_medscape.frontend'); | |
// create authmap | |
$profile = vod_oauth_medscape_SESSION_GET(VOD_AUTH_MEDSCAPE_SESSION_KEY_PROFILE); | |
if ($profile) { | |
vod_oauth_medscape_update_authmap($profile->guid, $account->uid); | |
} | |
} function vod_oauth_medscape_form_user_register_form_alter(&$form, &$form_state, $form_id) | |
{ | |
module_load_include('inc', 'vod_oauth_medscape', 'vod_oauth_medscape.frontend'); | |
// zip code is optional and only applicable when $profile is available, in which case we have a value | |
// hide always on register; medscape or not | |
$form['field_zip_code']['#attributes']['style'] = array('display:none;'); | |
// if oauth profile exists, use it | |
$profile = vod_oauth_medscape_SESSION_GET(VOD_AUTH_MEDSCAPE_SESSION_KEY_PROFILE); | |
if ($profile) | |
{ | |
// set default values, and hide fields. Can't simply change field type to 'hidden' .. drupal no likey | |
$form['field_first_name']['und'][0]['value']['#default_value'] = $profile->fn; | |
$form['field_first_name']['#attributes']['style'] = array('display:none;'); | |
$form['field_last_name']['und'][0]['value']['#default_value'] = $profile->ln; | |
$form['field_last_name']['#attributes']['style'] = array('display:none;'); | |
$form['field_zip_code']['und'][0]['value']['#default_value'] = $profile->zc; | |
// remove fields from form | |
$form['field_therapeutic_areas']['#access'] = FALSE; | |
$form['field_specialities']['#access'] = FALSE; | |
$form['field_npi_number']['#access'] = FALSE; | |
$form['field_state']['#access'] = FALSE; | |
$form['field_grants']['#access'] = FALSE; | |
} | |
//show for all user reg forms | |
$form['terms_of_use'] = array( | |
'#type' => 'item', | |
'#markup' => '<div class="term">By submitting this form, you acknowledge that you have read, understand, and agree to the ConneXion360 <a href="/terms-of-use">Terms of Use</a> and <a href="/privacy-policy">Privacy Policy.</a> </div>', | |
'#weight' => 10, | |
); | |
} | |
//example two changing search variables | |
function diabetes30_form_alter(&$form, &$form_state, $form_id) | |
{ | |
if ($form_id == 'search_block_form') | |
{ | |
$form['search_block_form']['#title'] = t('Search'); // Change the text on the label element | |
$form['search_block_form']['#title_display'] = 'invisible'; // Toggle label visibilty | |
$form['search_block_form']['#size'] = 30; // define size of the textfield | |
$form['search_block_form']['#default_value'] = t('Search'); // Set a default value for the textfield | |
$form['actions']['submit']['#value'] = t(''); // Change the text on the submit button | |
$form['actions']['submit'] = array('#type' => 'image_button', '#src' => base_path() . path_to_theme() . '/images/btn-search.png'); | |
// Add extra attributes to the text box | |
$form['search_block_form']['#attributes']['onblur'] = "if (this.value == '') {this.value = 'Search';}"; | |
$form['search_block_form']['#attributes']['onfocus'] = "if (this.value == 'Search') {this.value = '';}"; | |
// Prevent user from searching the default text | |
$form['#attributes']['onsubmit'] = "if(this.search_block_form.value=='Search'){ alert('Please enter a search'); return false; }"; | |
// Alternative (HTML5) placeholder attribute instead of using the javascript | |
$form['search_block_form']['#attributes']['placeholder'] = t('Search'); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment