diff options
author | Prashant S | 2016-05-23 15:11:17 +0530 |
---|---|---|
committer | Prashant S | 2016-05-23 15:11:17 +0530 |
commit | b7811bfbdfd48be8982b5fa187b61edac18e2087 (patch) | |
tree | 16ad5febabad9e1ae98f076d40f85b456743644d | |
parent | 9f4a7a11d99550ab348575ae96b0fba21ef738a2 (diff) | |
parent | 7f48f384f87eca8c57b11aacab7da3bc35469d4e (diff) | |
download | scilab_form_edit-b7811bfbdfd48be8982b5fa187b61edac18e2087.tar.gz scilab_form_edit-b7811bfbdfd48be8982b5fa187b61edac18e2087.tar.bz2 scilab_form_edit-b7811bfbdfd48be8982b5fa187b61edac18e2087.zip |
added interface to add new city in database
-rwxr-xr-x | form_edit.inc | 67 | ||||
-rwxr-xr-x | form_edit.module | 14 |
2 files changed, 81 insertions, 0 deletions
diff --git a/form_edit.inc b/form_edit.inc index 2ead0a0..e556687 100755 --- a/form_edit.inc +++ b/form_edit.inc @@ -1004,3 +1004,70 @@ function _completed_lab_proposal_edit_form_submit($form, &$form_state) drupal_set_message(t('Proposal Updated'), 'status'); } +// used to add new city in databse +function add_new_city_form($form,&$from_state) +{ + $form['new_city_name'] = array( + '#type' => 'textfield', + '#title' => t('Enter New City'), + '#size' => 50, + '#description' => t('Enter new city name in first letter in uppercase. Example - Mumbai'), + '#maxlength' => 30, + '#required' => False, + '#attributes' => array( + 'placeholder' => 'Enter new city name in ....' + ), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit') + ); + $form['cancel'] = array( + '#markup' => l(t('Cancel'), '') + ); + return $form; +} +function add_new_city_form_validate($form,&$form_state) +{ + $new_city_name = $form_state['values']['new_city_name']; + if (!preg_match("/^[a-zA-Z ]*$/", $new_city_name)) + { + form_set_error('new_city_name', t('Only letters are allowed')); + } + $form_state['values']['new_city_name'] = nameize($new_city_name); + return; +} +function add_new_city_form_submit($form,&$form_state) +{ + if($form_state['values']['new_city_name']) + { + $query = "SELECT city FROM list_cities_of_india WHERE city = :city"; + $args = array(":city" => $form_state['values']['new_city_name']); + $result = db_query($query,$args)->fetchObject(); + if(!$result) + { + db_query("INSERT INTO {list_cities_of_india} (city) VALUES (:city)",array(":city" => $form_state['values']['new_city_name'])); + drupal_set_message("City has been added in database"); + } else + { + drupal_set_message("City already present in database","error"); + } + } +} +function nameize($str,$a_char = array("'","-"," ")){ + $string = strtolower($str); + foreach ($a_char as $temp){ + $pos = strpos($string,$temp); + if ($pos){ + //we are in the loop because we found one of the special characters in the array, so lets split it up into chunks and capitalize each one. + $mend = ''; + $a_split = explode($temp,$string); + foreach ($a_split as $temp2){ + //capitalize each portion of the string which was separated at a special character + $mend .= ucfirst($temp2).$temp; + } + $string = substr($mend,0,-1); + } + } + return ucfirst($string); +} diff --git a/form_edit.module b/form_edit.module index dd58953..f59f5ad 100755 --- a/form_edit.module +++ b/form_edit.module @@ -3,6 +3,20 @@ function form_edit_menu() { $items = array(); + $items['form_edit/add/city'] = array( + 'title' => 'Add new city in databse', + 'description' => 'Add new city in databse', + 'page callback' => 'drupal_get_form', + 'page arguments' => array( + 'add_new_city_form' + ), + 'access arguments' => array( + 'edit completed book proposal' + ), + 'type' => MENU_NORMAL_ITEM, + 'weight' => 2, + 'file' => 'form_edit.inc' + ); $items['form_edit/tbc/all'] = array( 'title' => 'All completed Proposals', 'description' => 'All completed Proposals', |