To create a web application where specific fields are input in Farsi and the rest of the data is displayed in a database with capabilities to search and delete entries, you can use HTML, CSS, JavaScript, and a server-side language like PHP or Node.js, along with a database like MySQL or MongoDB. Below, is a simple prototype using HTML, CSS, and JavaScript with Node.js and a MongoDB database.
Please note that this is a basic example, and for a complete application, you would need to handle various aspects like input validation, security, session management, etc.
Frontend: HTML and CSS
<!DOCTYPE html>
<html lang="fa">
<head>
<meta charset="UTF-8">
<title>App</title>
<style>
body {
direction: rtl;
font-family: 'Arial', sans-serif;
}
form {
margin: 20px;
}
input {
display: block;
margin: 10px 0;
padding: 5px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
}
</style>
</head>
<body>
<h2>فرم اطلاعات</h2>
<form id="infoForm">
<input type="text" id="name" placeholder="نام" required>
<input type="text" id="fatherName" placeholder="نام پدر" required>
<input type="text" id="nationalNumber" placeholder="شماره ملی" required>
<input type="text" id="birthdate" placeholder="تاریخ تولد" required>
<input type="text" id="contact" placeholder="شماره تماس" required>
<input type="text" id="address" placeholder="آدرس" required>
<input type="text" id="qualification" placeholder="مدرک تحصیلی" required>
<input type="text" id="position" placeholder="سمت" required>
<button type="button" onclick="saveData()">ذخیره</button>
</form>
<h2>لیست اطلاعات</h2>
<input type="text" id="search" placeholder="جستجو" oninput="searchData()">
<table>
<thead>
<tr>
<th>حذف</th>
<th>نام</th>
<th>نام پدر</th>
<th>شماره ملی</th>
<th>تاریخ تولد</th>
<th>شماره تماس</th>
<th>آدرس</th>
<th>مدرک تحصیلی</th>
<th>سمت</th>
</tr>
</thead>
<tbody id="dataList">
</tbody>
</table>
<script>
function saveData() {
// For simplicity, using local data, replace with API call to save data
const data = {
name: document.getElementById('name').value,
fatherName: document.getElementById('fatherName').value,
nationalNumber: document.getElementById('nationalNumber').value,
birthdate: document.getElementById('birthdate').value,
contact: document.getElementById('contact').value,
address: document.getElementById('address').value,
qualification: document.getElementById('qualification').value,
position: document.getElementById('position').value,
};
// Post this data to a server or save in a database
console.log('Data saved:', data);
}
function loadData() {
// Simulate loading from a database
const data = [
// Sample data
];
const tbody = document.getElementById('dataList');
tbody.innerHTML = ''; // clear previous data
data.forEach(item => {
const tr = document.createElement('tr');
tr.innerHTML = `
<td><button onclick="deleteData('${item.nationalNumber}')">X</button></td>
<td>${item.name}</td>
<td>${item.fatherName}</td>
<td>${item.nationalNumber}</td>
<td>${item.birthdate}</td>
<td>${item.contact}</td>
<td>${item.address}</td>
<td>${item.qualification}</td>
<td>${item.position}</td>
`;
tbody.appendChild(tr);
});
}
function deleteData(nationalNumber) {
// Remove item with this nationalNumber from the database
console.log('Delete:', nationalNumber);
}
function searchData() {
const query = document.getElementById('search').value.toLowerCase();
// Implement search functionality
console.log('Search query:', query);
}
document.addEventListener('DOMContentLoaded', loadData);
</script>
</body>
</html>
Backend: Node.js and MongoDB
You'll need to set up a Node.js server with Express.js and connect it to a MongoDB database. Here's a basic setup:
- Set up your Node.js environment:
mkdir app
cd app
npm init -y
npm install express mongoose body-parser cors
- Create a server script
server.js:
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = process.env.PORT || 3000;
app.use(cors());
app.use(bodyParser.json());
// Replace with your MongoDB connection string
mongoose.connect('mongodb://localhost:27017/dataApp', { useNewUrlParser: true, useUnifiedTopology: true });
const dataSchema = new mongoose.Schema({
name: String,
fatherName: String,
nationalNumber: String,
birthdate: String,
contact: String,
address: String,
qualification: String,
position: String
});
const Data = mongoose.model('Data', dataSchema);
app.post('/data', async (req, res) => {
const data = new Data(req.body);
await data.save();
res.send(data);
});
app.get('/data', async (req, res) => {
const data = await Data.find();
res.send(data);
});
app.delete('/data/:id', async (req, res) => {
await Data.findByIdAndDelete(req.params.id);
res.send({ message: 'Deleted' });
});
app.listen(port, () => {
console.log(`Server listening at http://localhost:${port}`);
});
- Start your server:
node server.js
This simple setup provides an interface for a web application to capture information in Farsi, save it to a database, and provide the ability to view, search, and delete records. In a real-world application, you'll need to expand this example with additional front-end functionalities and proper backend error handling and security measures.