t('Add Member'), 'path' => 'add_member', 'callback' => 'drupal_get_form', 'callback arguments' => array('add_member_multiform'), 'access' => TRUE, ); $items[] = array( 'title' => t('Thanks!'), 'path' => 'add_member/thanks', 'callback' => 'add_member_thanks', 'type' => MENU_CALLBACK, 'access' => user_access('access_content') ); } return $items; } /** * Build the form differently depending on which step we're on. */ function add_member_multiform($form_values = NULL) { $form['#multistep']= TRUE; // Find out which step we are on. If $form_value is NULL // that mean we are on step 1. $step = isset($form_values) ? (int) $form_values['step'] : 1; $form_type = isset($form_values) ? (string) $form_values['form_type'] : "Add Member Particulars"; // Store next step in hidden field. $form['step'] = array ( '#type' => 'hidden', '#value' => $step + 1 ); // Store next form type in hidden field. $form['form_type'] = array ( '#type' => 'hidden', '#value' => "Add Parent Particulars" ); // Customise the fieldset title to indicate the current step to the user $form['indicator'] = array( '#type' => 'fieldset', '#title' => t('Step @number : @type', array('@number' => $step, '@type' => $form_type)) ); // The name of our ingredient form element is unique for // each step, e.g. , ingredient_1, ingredient_2... switch($step){ case 1: $form['#attributes'] = array('enctype' => "multipart/form-data"); $form['indicator']['member_name'] = array( '#type' => 'textfield', '#title' => t('Full Name'), '#description' => t('Enter New Member Full Name'), '#required' => TRUE ); $form['indicator']['image'] = array( '#type' => 'file', '#title' => t('Photo'), '#description' => t('browse photo') ); $form['indicator']['nric'] = array( '#type' => 'textfield', '#title' => t('NIRC'), '#description' => t('Enter a 8 Character NRIC'), '#required' => TRUE ); $form['indicator']['gender'] = array( '#title' => t('Gender'), '#type' => 'radios', '#options' => array(t('male'),t('female')), '#required' => TRUE ); $form['indicator']['address'] = array( '#title' => t('Address'), '#type' => 'textfield', '#description' => t('Please enter Address'), '#required' => TRUE ); $form['indicator']['contact_number'] = array( '#title' => t('Contact Number'), '#type' => 'textfield', '#description' => t('Please enter Contact Number'), '#required' => TRUE ); $form['indicator']['dob'] = array( '#title' => t('Date Of Birth'), '#type' => 'textfield', '#description' => t('Please enter by DD/MM/YY'), '#required' => TRUE ); $form['indicator']['sec_sch'] = array( '#title' => t('Secondary School Name'), '#type' => 'textfield', '#description' => t('Please enter Secondary School Name'), '#required' => TRUE ); $form['indicator']['class'] = array( '#title' => t('Class in School'), '#type' => 'textfield', '#description' => t('Please enter the Class that Member is in'), '#required' => TRUE ); $form['indicator']['religon'] = array( '#title' => t('Religon'), '#type' => 'radios', '#description' => t('Please enter Religon'), '#options' => array(t('Buddhist'),t('Christian'),t('Catholic'),t('Hindu'),t('Islam'),t('Sikh'),t('Taoist'),t('Freethinker')), '#required' => TRUE ); $form['indicator']['medical'] = array( '#title' => t('Medical History'), '#type' => 'textfield', '#description' => t('Please enter Medical History'), '#required' => TRUE ); break; case 2: $form['indicator']['father_name'] = array( '#title' => t('Father Name'), '#type' => 'textfield', '#description' => t('Please enter Father Name') ); $form['indicator']['father_nric'] = array( '#title' => t('Father NRIC'), '#type' => 'textfield', '#description' => t('Please enter Father NRIC') ); $form['indicator']['father_contact'] = array( '#title' => t('Father Contact Number'), '#type' => 'textfield', '#description' => t('Please enter Father Contact Number') ); $form['indicator']['father_occupation'] = array( '#title' => t('Father Occupation'), '#type' => 'textfield', '#description' => t('Please enter Father Occupation') ); $form['indicator']['mother_name'] = array( '#title' => t('Mother Name'), '#type' => 'textfield', '#description' => t('Please enter Mother Name') ); $form['indicator']['mother_nric'] = array( '#title' => t('Mother NRIC'), '#type' => 'textfield', '#description' => t('Please enter Mother NRIC') ); $form['indicator']['mother_contact'] = array( '#title' => t('Mother Contact Number'), '#type' => 'textfield', '#description' => t('Please enter Mother Contact Number') ); $form['indicator']['mother_occupation'] = array( '#title' => t('Mother Occupation'), '#type' => 'textfield', '#description' => t('Please enter Mother Occupation') ); $form['indicator']['housing_type'] = array( '#title' => t('Housing Type'), '#type' => 'textfield', '#description' => t('Please enter Housing Type') ); } // The button will say Next until the last step, when it will say Submit. // Also, we trun off redirection until the last step. $button_name = t('Submit'); if($step < 2){ $form['#redirect'] = FALSE; $button_name = t('Next'); } $form['submit'] = array( '#type' => 'submit', '#value' => $button_name ); switch($step){ case 2: $form['member_name'] = array( '#type' => 'hidden', '#value' => $form_values['member_name'] ); $form['image'] = array( '#type' => 'hidden', '#value' => $form_values['image'] ); $form['nric'] = array( '#type' => 'hidden', '#value' => $form_values['nric'] ); $form['gender'] = array( '#type' => 'hidden', '#value' => $form_values['gender'] ); $form['address'] = array( '#type' => 'hidden', '#value' => $form_values['address'] ); $form['contact_number'] = array( '#type' => 'hidden', '#value' => $form_values['contact_number'] ); $form['indicator']['dob'] = array( '#type' => 'hidden', '#value' => $form_values['dob'] ); $form['sec_sch'] = array( '#type' => 'hidden', '#value' => $form_values['sec_sch'] ); $form['class'] = array( '#type' => 'hidden', '#value' => $form_values['class'] ); $form['religon'] = array( '#type' => 'hidden', '#value' => $form_values['religon'] ); $form['medical'] = array( '#type' => 'hidden', '#value' => $form_values['medical'] ); } return $form; } /** * Validate handler for form ID 'formwizard_multiform'. */ function add_member_multiform_validate($form_id, $form_values){ drupal_set_message(t('Validation called for step @step', array('@step' => $form_values['step'] -1))); } /** * Submit handler for form ID 'formwizard_multiform'. */ function add_member_multiform_submit($form_id,$form_values){ if($form_values['step'] < 3){ return; } $name = $form_values['member_name']; $image = $form_values['image']; $nric = $form_values['nric']; $gender = $form_values['gender']; $address = $form_values['address']; $contact = $form_values['contact_number']; $dob = $form_values['dob']; $class = $form_values['class']; $sch = $form_values['sec_sch']; $religon = $form_values['religon']; $medical = $form_values['medical']; $f_name = $form_values['father_name']; $f_nric = $form_values['father_nric']; $f_contact = $form_values['father_contact']; $f_occupation = $form_values['father_occupation']; $m_name = $form_values['mother_name']; $m_nric = $form_values['mother_nric']; $m_contact = $form_values['mother_contact']; $m_occupation = $form_values['mother_occupation']; $housing_type = $form_values['housing_type']; db_query("INSERT INTO {member} (full_name, nric, gender, address, contact_number, date_of_birth, secondary_school, class, image, religon, medical_history, father_name, father_nric, father_occupation, father_contact, mother_name, mother_nric, mother_contact, mother_occupation, housing_type) VALUES ('%s', '%s', '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, '%s', '%s', %d, '%s', '%s')", $name, $nric, $gender, $address, $contact, $dob, $sch, $class, $image, $religon, $medical, $f_name, $f_nric, $f_occupation, $f_contact, $m_name, $m_nric, $m_contact, $m_occupation, $housing_type); drupal_set_message(t('Member has suadhfahf')); return 'add_member/thanks'; } function add_member_thanks(){ return t('Thanks, and have a nice day.'); }