Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //function registration_install(){}
- //function registration_uninstall(){}
- //diplay help content
- function registration_help($path) {
- $output = ''; //declare your output variable
- switch ($path) {
- case "admin/help#registration":
- $output = '<p>'. t("Get the user data with a simple registration form .") .'</p>';
- break;
- }
- return $output;
- } // function registration_help
- // Valid permissions for this module
- function registration_perm() {
- return array('access registration content', 'create registration', 'administer registration');
- } // function registration_perm()
- /**
- * drupal_get_form() callback. No need to pass $form and $form_state as they are not used.
- */
- function registration_register_form(){
- $form = array();
- $form[name] = array(
- '#type' => 'textfield',
- '#title' => t('Enter your name'),
- '#maxlength' => 30,
- '#required' => TRUE,
- '#size' => 20,
- );
- $form[family] = array(
- '#type' => 'textfield',
- '#title' => t('Enter your family name:'),
- '#maxlength' =>50,
- '#required' => TRUE,
- '#size' => 20,
- );
- $form[id] = array(
- '#type' => 'textfield',
- '#title' => t('Enter your ID number:'),
- '#maxlength' => 8,
- '#required' => TRUE,
- '#size' => 8,
- '#element_validate' => array('numric_validate'),
- '#ahah' => array(
- 'event' => 'focusout',
- 'path' => 'registration/js_idcheck',
- 'wrapper' => 'div_idcheck',
- 'method' => 'replace',
- 'effect' => 'fade'),
- );
- $form['div_idcheck'] = array(
- '#type' => 'value',
- '#value' => '<div id="div_idcheck"></div>',
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('send'),
- );
- return $form;
- }//registration_form
- /**
- * submit handler for registration_register_form().
- * no need to pass $form_state by reference.
- * corrected some sql injection stuff.
- * removed validation stuff for #required fields as they are required above.
- */
- function registration_register_form_submit($form, $form_state){
- $id = $form_state['values']['id'];
- $name_f = $form_state['values']['name'];
- $family = $form_state['values']['family'];
- // not necessary tovalidate #required = TRUE fields/
- $sql='SELECT * FROM {registration} WHERE id = %d';
- $result=db_query($sql, $id);
- if(db_num_rows($result) != 0){
- form_set_error('id' , 'Your entered id is already exist');
- return;
- }
- db_query("INSERT INTO {registration} (name, family, id) VALUES ('%s', %s, %d)", $name_f,$family,$id);
- if (db_error === FALSE) // what ?
- drupal_set_message(t('Your form has been saved.'));
- else
- drupal_set_message(t('some error happen.please retry again.'), 'error');
- }
- function registration_admin_settings() {
- return 0;
- }//registration_admin_settings
- function registration_menu() {
- $items = array();
- /*$items['admin/settings/registration'] = array(
- 'title' => 'View the successful registration.',
- 'description' => 'Show the list of registred forms',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('registration_admin_setting'),
- 'access arguments' => array('administer registration settings'),
- 'type' => MENU_NORMAL_ITEM,
- );
- * */
- //link for registration form
- $items['registration'] = array(
- 'title' => 'Registration form',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('registration_register_form'),
- 'access arguments' => array('access registration content'),
- 'type' => MENU_NORMAL_ITEM,
- );
- //link for submit validate script
- /* $items['registration/js_submit'] = array(
- 'page callback' => 'js_submit',
- 'access arguments' => array('access mymodule js'),
- 'type' => MENU_CALLBACK,
- );*/
- //link for user id validate script
- $items['registration/js_idcheck'] = array(
- 'page callback' => 'js_idcheck',
- 'access arguments' => array('access mymodule js'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
- }//registration_menu
- //check id field for duplicate entery in database
- function js_idcheck(){
- $id=$form_state[values][id];
- $sql="select * from {registration} where id = $id";
- $result = db_query($sql);
- if(db_num_rows($result) != 0)
- return drupal_json(array('status' => FALSE, 'data' => "This ID is already existing in database."));
- else
- return drupal_json(array('status' => TRUE, 'data' => "This ID is new."));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement