Guest User

Revision

a guest
Oct 19th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.97 KB | None | 0 0
  1. <?php
  2.  
  3. //function registration_install(){}
  4. //function registration_uninstall(){}
  5.  
  6. //diplay help content
  7. function registration_help($path, $arg) {
  8.   $output = '';  //declare your output variable
  9.   switch ($path) {
  10.     case "admin/help#registration":
  11.       $output = '<p>'.  t("Get the user data with a simple registration form .") .'</p>';
  12.       break;
  13.   }
  14.   return $output;
  15. } // function registration_help
  16.  
  17.  
  18.  
  19. // Valid permissions for this module
  20. function registration_perm() {
  21.   return array('access registration', 'create registration', 'administer registration');
  22. } // function registration_perm()
  23.  
  24. function registration_register_form(){
  25.     $form = array();
  26.  
  27.     $form[name] = array(
  28.     '#type' => 'textfield',
  29.     '#title' => t('Enter your name'),
  30.     '#maxlength' => 30,
  31.     '#required' => TRUE,
  32.     '#size' => 20,
  33.     );
  34.    
  35.     $form[family] = array(
  36.     '#type' => 'textfield',
  37.     '#title' => t('Enter your family name:'),
  38.     '#maxlength' =>50',
  39.     '#required' => TRUE,
  40.     '#size' => 20,
  41.     );
  42.  
  43.     $form[id] = array(
  44.     '#type' => 'textfield',
  45.     '#title' => t('Enter your ID number:'),
  46.     '#maxlength' => 8,
  47.     '#required' => TRUE,
  48.     '#size' => '8,
  49.     '#element_validate' => array('numric_validate'),
  50.     '#ahah' => array(
  51.           'event' => 'focusout',
  52.           'path' => 'registration/js_idcheck',
  53.           'wrapper' => 'div_idcheck',
  54.           'method' => 'replace',
  55.           'effect' => 'fade'),
  56.     );
  57.    
  58.     $form['div_idcheck'] = array(
  59.     '#type' => 'value',
  60.     '#value' => '<div id="div_idcheck"></div>',
  61.     );
  62.      
  63.     $form['submit'] = array(
  64.     '#type' => 'submit',
  65.     '#value' => t('send'),
  66.     );
  67. return $form;
  68. }//registration_form
  69.  
  70. function registration_register_form_submit($form, &$form_state){
  71.     $id=$form_state[values][id];
  72.     $name_f=$form_state[values][name];
  73.     $family=$form_state[values][family];
  74.    
  75.     // not necessary tovalidate #required = TRUE fields/
  76.     $sql='select * from {registration} where id = %d';
  77.     $result=db_query($sql, $id);
  78.     if(db_num_rows($result) != 0)
  79.         form_set_error(id , 'Your entered id is already exist', FALSE);
  80.        
  81.     db_query("INSERT INTO {registration} (name, family, id) VALUES ('%s', %s, '%d')", $name_f,$family,$id);
  82.     if (db_error === FALSE)
  83.         drupal_set_message(t('Your form has been saved.'));
  84.     else
  85.         drupal_set_message(t('some error happen.please retry again.'), 'error');
  86. }
  87.  
  88.  
  89. function registration_admin_settings() {
  90.  
  91.  return 0;  
  92. }//registration_admin_settings
  93.  
  94. function registration_menu() {
  95.  
  96.   $items = array();
  97.  
  98.   /*$items['admin/settings/registration'] = array(
  99.     'title' => 'View the successful registration.',
  100.     'description' => 'Show the list of registred forms',
  101.     'page callback' => 'drupal_get_form',
  102.     'page arguments' => array('registration_admin_setting'),
  103.     'access arguments' => array('administer registration settings'),
  104.     'type' => MENU_NORMAL_ITEM,
  105.    );
  106.    * */
  107.  
  108.   //link for registration form
  109.   $items['registration'] = array(
  110.     'title' => 'Registration form',
  111.     'page callback' => 'drupal_get_form',
  112.         'page arguments' => array('registration_register_form'),
  113.     'access arguments' => array('access registration content'),
  114.     'type' => MENU_NORMAL_ITEM,
  115.   );
  116.  
  117.   //link for submit validate script
  118. /*   $items['registration/js_submit'] = array(
  119.     'page callback' => 'js_submit',
  120.     'access arguments' => array('access mymodule js'),
  121.     'type' => MENU_CALLBACK,
  122.   );*/
  123.  
  124.   //link for user id validate script
  125.    $items['registration/js_idcheck'] = array(
  126.     'page callback' => 'js_idcheck',
  127.     'access arguments' => array('access mymodule js'),
  128.     'type' => MENU_CALLBACK,
  129.   );
  130.  
  131.   return $items;
  132. }//registration_menu
  133.  
  134. //check id field for duplicate entery in database
  135. function js_idcheck(){
  136.     $id=$form_state[values][id];
  137.     $sql="select * from {registration} where id = $id";
  138.    
  139.     $result = db_query($sql);
  140.     if(db_num_rows($result) != 0)
  141.         return drupal_json(array('status' => FALSE, 'data' => "This ID is already existing in database."));
  142.     else
  143.         return drupal_json(array('status' => TRUE, 'data' => "This ID is new."));
  144. }
Advertisement
Add Comment
Please, Sign In to add comment