false, 'message' => 'Membership type is required']); exit; } $membership_type = sanitizeInput($_GET['membership_type']); $valid_memberships = ['active', 'gram_panchayat', 'block', 'tehsil', 'district', 'mandal', 'state', 'national']; if (!in_array($membership_type, $valid_memberships)) { echo json_encode(['success' => false, 'message' => 'Invalid membership type']); exit; } try { $designations = getDesignationsByMembershipType($membership_type); echo json_encode(['success' => true, 'designations' => $designations]); } catch (Exception $e) { logError('Error fetching designations: ' . $e->getMessage()); echo json_encode(['success' => false, 'message' => 'Failed to fetch designations']); } exit; } // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'register_user') { header('Content-Type: application/json'); if (!verifyCSRF($_POST['csrf_token'])) { logError('Invalid CSRF token in user apply form submission'); echo json_encode(['success' => false, 'message' => 'Invalid CSRF token']); exit; } // Validate required fields $required_fields = ['membership_charge', 'payment_method', 'Name', 'Gender', 'Dob', 'sdw_type', 'sdw_name', 'Mobile', 'Aadhar_no', 'State', 'City', 'Address', 'Pincode', 'designation', 'Password', 'Email', 'Working_area']; foreach ($required_fields as $field) { if (empty($_POST[$field])) { logError("Missing required field: $field"); echo json_encode(['success' => false, 'message' => "Please fill the '$field' field"]); exit; } } $membership_type = sanitizeInput($_POST['membership_charge']); $payment_method = sanitizeInput($_POST['payment_method']); $name = sanitizeInput($_POST['Name']); $gender = sanitizeInput($_POST['Gender']); $dob = sanitizeInput($_POST['Dob']); $sdw_type = sanitizeInput($_POST['sdw_type']); $sdw_name = sanitizeInput($_POST['sdw_name']); $profession = !empty($_POST['Profession']) ? sanitizeInput($_POST['Profession']) : null; $blood_group = !empty($_POST['Blood_group']) ? sanitizeInput($_POST['Blood_group']) : null; $mobile = sanitizeInput($_POST['Mobile']); $aadhar_no = sanitizeInput($_POST['Aadhar_no']); $state = sanitizeInput($_POST['State']); $city = sanitizeInput($_POST['City']); $address = sanitizeInput($_POST['Address']); $pincode = sanitizeInput($_POST['Pincode']); $email = sanitizeInput($_POST['Email']); $password = password_hash(sanitizeInput($_POST['Password']), PASSWORD_DEFAULT); $designation = sanitizeInput($_POST['designation']); $working_area = sanitizeInput($_POST['Working_area']); $order_id = !empty($_POST['order_id']) ? sanitizeInput($_POST['order_id']) : null; $payment_id = !empty($_POST['payment_id']) ? sanitizeInput($_POST['payment_id']) : null; $status = ($payment_method === 'online') ? 'approved' : 'pending'; $user_type = 'member'; $valid_until = ($payment_method === 'online') ? date('Y-m-d', strtotime('+1 year')) : null; $profile_image = null; $aadhar_front = null; $aadhar_back = null; $payment_proof = null; // Validate email format if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { logError("Invalid email format: $email"); echo json_encode(['success' => false, 'message' => 'Please enter a valid email address']); exit; } // Validate mobile, Aadhaar, and pincode if (!preg_match('/^[0-9]{10}$/', $mobile)) { logError("Invalid mobile number: $mobile"); echo json_encode(['success' => false, 'message' => 'Mobile number must be 10 digits']); exit; } if (!preg_match('/^[0-9]{12}$/', $aadhar_no)) { logError("Invalid Aadhaar number: $aadhar_no"); echo json_encode(['success' => false, 'message' => 'Aadhaar number must be 12 digits']); exit; } if (!preg_match('/^[0-9]{6}$/', $pincode)) { logError("Invalid pincode: $pincode"); echo json_encode(['success' => false, 'message' => 'Pincode must be 6 digits']); exit; } // Check for duplicate Aadhaar, mobile, or email try { $stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE aadhar = ? OR mobile = ? OR email = ?"); $stmt->execute([$aadhar_no, $mobile, $email]); if ($stmt->fetchColumn() > 0) { logError("Duplicate Aadhaar ($aadhar_no), mobile ($mobile), or email ($email)"); echo json_encode(['success' => false, 'message' => 'Aadhaar, mobile number, or email already registered']); exit; } } catch (PDOException $e) { logError('Error checking duplicates: ' . $e->getMessage()); echo json_encode(['success' => false, 'message' => 'Failed to validate Aadhaar/mobile/email. Please try again.']); exit; } // Validate membership type $valid_memberships = ['active', 'gram_panchayat', 'block', 'tehsil', 'district', 'mandal', 'state', 'national']; if (!in_array($membership_type, $valid_memberships)) { logError("Invalid membership type: $membership_type"); echo json_encode(['success' => false, 'message' => 'Invalid membership type']); exit; } // Validate designation $valid_designations = array_column(getDesignationsByMembershipType($membership_type), 'designation'); if (!in_array($designation, $valid_designations)) { logError("Invalid designation: $designation for membership type: $membership_type"); echo json_encode(['success' => false, 'message' => 'Invalid designation']); exit; } // Handle file uploads with enhanced validation $required_files = [ 'Profile' => 'profile_image', 'Aadhar_front' => 'aadhar_front', 'Aadhar_back' => 'aadhar_back' ]; foreach ($required_files as $file_field => $db_field) { if (!empty($_FILES[$file_field]['name']) && $_FILES[$file_field]['error'] === UPLOAD_ERR_OK) { $extension = strtolower(pathinfo($_FILES[$file_field]['name'], PATHINFO_EXTENSION)); $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'pdf']; if (!in_array($extension, $allowed_extensions)) { logError("Invalid file extension for $file_field: $extension"); echo json_encode(['success' => false, 'message' => "Invalid file type for $file_field. Only JPG, PNG, GIF, and PDF allowed."]); exit; } $uploadResult = uploadFile($_FILES[$file_field], 'Uploads/profiles'); if ($uploadResult['success']) { $$db_field = $uploadResult['filename']; } else { logError("File upload failed for $file_field: " . $uploadResult['message']); echo json_encode(['success' => false, 'message' => $uploadResult['message']]); exit; } } else { logError("Missing or invalid file upload for $file_field"); echo json_encode(['success' => false, 'message' => "$file_field is required"]); exit; } } // Handle payment proof for offline payments if ($payment_method === 'offline') { if (!empty($_FILES['payment_proof']['name']) && $_FILES['payment_proof']['error'] === UPLOAD_ERR_OK) { $extension = strtolower(pathinfo($_FILES['payment_proof']['name'], PATHINFO_EXTENSION)); $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'pdf']; if (!in_array($extension, $allowed_extensions)) { logError("Invalid file extension for payment_proof: $extension"); echo json_encode(['success' => false, 'message' => "Invalid file type for payment proof. Only JPG, PNG, GIF, and PDF allowed."]); exit; } $uploadResult = uploadFile($_FILES['payment_proof'], 'uploads/payments'); if ($uploadResult['success']) { $payment_proof = $uploadResult['filename']; } else { logError('Payment proof upload failed: ' . $uploadResult['message']); echo json_encode(['success' => false, 'message' => $uploadResult['message']]); exit; } } else { logError('Missing payment proof for offline payment'); echo json_encode(['success' => false, 'message' => 'Payment proof is required for offline payments']); exit; } } // Generate unique registration ID do { $registration_id = 'SCF' . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT); $stmt = $db->prepare("SELECT COUNT(*) FROM users WHERE registration_id = ?"); $stmt->execute([$registration_id]); } while ($stmt->fetchColumn() > 0); try { $stmt = $db->prepare(" INSERT INTO users ( name, email, password, mobile, gender, dob, sdw_type, sdw_name, profession, designation, blood_group, aadhar, state, district, address, pincode, membership_type, profile_image, aadhar_front, aadhar_back, order_id, payment_id, payment_proof, payment_method, registration_id, status, user_type, valid_until, created_at, working_area ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), ?) "); $stmt->execute([ $name, $email, $password, $mobile, $gender, $dob, $sdw_type, $sdw_name, $profession, $designation, $blood_group, $aadhar_no, $state, $city, $address, $pincode, $membership_type, $profile_image, $aadhar_front, $aadhar_back, $order_id, $payment_id, $payment_proof, $payment_method, $registration_id, $status, $user_type, $valid_until, $working_area ]); $user_id = $db->lastInsertId(); echo json_encode([ 'success' => true, 'data' => [ 'registration_id' => $registration_id, 'user_id' => $user_id, 'receipt_url' => $status === 'approved' ? SITE_URL . '/generate_receipt.php?user_id=' . $user_id . '&type=registration' : null ] ]); } catch (PDOException $e) { logError('User registration error: ' . $e->getMessage()); echo json_encode(['success' => false, 'message' => 'Failed to save registration. Please try again.']); } exit; } include 'header.php'; include 'navbar.php'; ?>

Registration Form

Membership Selection
Designation Selection

Payment Method

Personal Details
Working Area

Professional Details

Contact & Address

Image uploads
Profile Picture *
Preview
Aadhaar Card (Front) *
Preview
Aadhaar Card (Back) *
Preview

Payment Information

Membership Rules & Bank Details

Bank Name:
A/c Name:
A/c No.:
IFSC Code:

Scan to Pay (Offline)
QR Code

Membership Fees:
  • Active Membership:/-
  • Gram Panchayat Level:/-
  • Block Level:/-
  • Tehsil Level:/-
  • District Level:/-
  • Mandal Level:/-
  • State Level:/-
  • National Level:/-

Note: After submitting the form and completing payment, you will receive a registration ID. You can use this ID to download your I-Card and appointment letter from the website after 24 hours. For offline payments, please upload proof of payment to verify your transaction.

Offline Payment Proof
Preview
Submit Button
Success Modal Image Preview Modal Spinner Loader
Loading...