Last active
August 29, 2015 14:23
-
-
Save vijaycs85/ef37d9aa757adc3b1de8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// playground.module | |
function playground_form_alter(&$form, &$form_state, $form_id) { | |
switch($form_id) { | |
case 'webform_client_form_1': | |
global $user; | |
if ($user->uid < 0) { | |
$form['submitted']['username']['#access'] = FALSE; | |
} | |
$form['submitted']['username']['#ajax'] = array( | |
'wrapper' => 'webform-client-form', | |
'method' => 'replace', | |
'effect' => 'fade', | |
'event' => 'blur', | |
'callback' => '_playground_check_username', | |
); | |
break; | |
} | |
} | |
function _playground_check_username($form, &$form_state) { | |
$parents = $form_state['triggering_element']['#array_parents']; | |
array_pop($parents); | |
$element = &drupal_array_get_nested_value($form, $parents); | |
$exists = FALSE; | |
// $username = $element['#value']['username']; | |
$username= $form_state['values']['submitted']['username']; | |
if (!empty($username)) { | |
$exists = db_query('SELECT name FROM {users} WHERE name = :entered', array(':entered' => $username))->fetchField(); | |
} | |
$commands = array(); | |
if ($exists) { | |
form_error($element, 'Kullanıcı adı kayıtlı, lütfen başka bir kullanıcı adı seçin'); | |
$error_selector = '.webform-client-form'; | |
$commands[] = ajax_command_replace($error_selector, theme('status_messages'). drupal_render($element) ); | |
// Use below commands if you want to display in message region. | |
// $commands[] = ajax_command_replace($error_selector, drupal_render($element) ); | |
// $commands[] = ajax_command_remove('#messages'); | |
// $commands[] = ajax_command_before('#main-wrapper', '<div id="messages"><div class="section clearfix">' . theme('status_messages') . '<div></div>'); | |
return array('#type' => 'ajax', '#commands' => $commands); | |
} | |
} |
Author
vijaycs85
commented
Jun 23, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment