The Sentidos Café homepage includes a visitor registration form that lets guests sign in without a full page reload. When a user submits their details, theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Jimmy13anhelo/paginaweb2.github.io/llms.txt
Use this file to discover all available pages before exploring further.
saludar() function in buscador.js takes over: it validates the inputs in the browser, packages the data into a FormData object, and sends it to guardar_usuario.php via the Fetch API. The server processes the insert and echoes back the plain string EXITO on success, which the JavaScript uses to swap the form area for a confirmation message — all without interrupting the browsing experience.
End-to-End Registration Flow
User fills in the form
The registration section collects four fields:
- Nombres (
#reg-nombres) — first name, required - Apellidos (
#reg-apellidos) — last name, required - Edad (
#reg-edad) — age, required - Género (
#reg-genero) — optional; defaults to"No especificado"if left blank
saludar() fires on submit
Clicking the submit button calls
saludar() from buscador.js. The function reads and trims each field value, then runs a client-side validation check. If nombres, apellidos, or edad are empty, an alert() stops submission early. A temporary "⏳ Conectando con MySQL..." message is shown inside the #bloqueResultadoSaludo container while the request is in flight.Fetch POST to guardar_usuario.php
The four values are appended to a
FormData instance and sent as a POST request to guardar_usuario.php using the browser’s native fetch() API. No page reload occurs.Server inserts the row
guardar_usuario.php includes conexion.php, validates the incoming POST fields, and executes a parameterized INSERT using PDO prepared statements. On success it outputs the plain string EXITO with no surrounding HTML.JS renders feedback
The
.then(resultado => ...) callback inspects the trimmed response text. If it equals "EXITO", the #bloqueResultadoSaludo div is replaced with a success card showing the guest’s full name and a green "✓ Guardado en MySQL" confirmation. All four form inputs are cleared for the next visitor. Any other response string is treated as an error and displayed in red.The saludar() Function
This is the complete AJAX registration handler frombuscador.js:
FormData automatically sets the Content-Type header to multipart/form-data with the correct boundary, so no manual headers need to be added to the fetch() call. PHP reads the values from $_POST as usual.The guardar_usuario.php Endpoint
guardar_usuario.php must live in the same directory as conexion.php and index.php. It accepts POST fields nombres, apellidos, edad, and genero, and returns only the bare string EXITO (no HTML, no whitespace before <?php) on a successful database insert.
The default
script.sql schema only defines three tables: pedidos, reservas, and usuarios. There is no visitantes table in the shipped schema. The example below targets a visitantes table that stores the four form fields (nombres, apellidos, edad, genero) plus an automatic timestamp. Before running this endpoint you must add the table to your database — either by running the CREATE TABLE statement shown below, or by adapting the INSERT to target a table that already exists in your schema.POST Fields Reference
| Field | PHP Variable | Type | Notes |
|---|---|---|---|
nombres | $nombres | string | Required; empty string fails server-side check |
apellidos | $apellidos | string | Required; empty string fails server-side check |
edad | $edad | int | Cast with (int) — must be greater than 0 |
genero | $genero | string | Optional; defaults to "No especificado" |
Response Strings
| Response | Meaning |
|---|---|
EXITO | Row inserted successfully |
ERROR: Datos incompletos. | Server-side validation failed |
ERROR: <PDOException message> | Database query failed |
Payroll Calculator (calcularYMostrar)
buscador.js also contains a staff payroll utility used by café management to estimate income tax withholding. It reads an employee name and gross salary from the page, applies Peruvian tax brackets, and populates a results table — all client-side with no server round-trip.
All monetary amounts in this calculator are in Peruvian Sol (S/), the official currency of Peru. The tax brackets are simplified estimates and should be validated against current SUNAT regulations before use in official payroll processing.
Tax Brackets
| Gross Salary Range | Withholding Rate | Status |
|---|---|---|
| S/ 0 – S/ 1,500 | 0% | Exonerado (exempt) |
| S/ 1,500.01 – S/ 3,000 | 8% | Sujeto a Retención |
| Over S/ 3,000 | 14% | Sujeto a Retención |
Implementation
#nombre, computes estado ("Exonerado" or "Sujeto a Retención"), and writes all five output values to their respective #out* elements before revealing the results table with tabla.style.display = "table".
Example Calculation
For an employee with a gross salary of S/ 2,200:- Tax bracket: S/ 1,500 – S/ 3,000 → 8%
- Tax amount:
2200 × 0.08= S/ 176.00 - Net salary:
2200 − 176= S/ 2,024.00 - Status: Sujeto a Retención