Skip to main content

Overview

The Contacts module stores and manages contact form submissions from your website. Track inquiries with country, phone, and email information for follow-up and customer service.

Key Features

Contact Submissions

Receive and store contact form data

Country Validation

Validate contacts against country database

Pagination

Browse contacts with configurable page sizes

CRUD Operations

View, create, update, and delete contact records

Contact Record Structure

Each contact submission includes:
  • Country (pais): Contact’s country
  • Phone (telefono): Contact phone number
  • Email (correo): Contact email address
  • Created At: Submission timestamp
{
  "id": 1,
  "pais": "Mexico",
  "telefono": "+52 55 1234 5678",
  "correo": "contact@example.com",
  "created_at": "2024-01-20T15:30:00Z"
}

Creating a Contact

1

Access Contacts Module

Navigate to Contacts from the sidebar menu.
2

Click 'New Contact'

Click the “Crear Contacto” button.
3

Fill Contact Information

Required fields:
  • Country (pais): Select from dropdown
  • Phone (telefono): Contact phone number
  • Email (correo): Valid email address
4

Submit Form

The system validates the country and creates the contact record.

Contact Creation Process

contactos.php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['crearContacto'])) {
    $pais = trim($_POST['pais'] ?? '');
    $telefono = trim($_POST['telefono'] ?? '');
    $correo = trim($_POST['correo'] ?? '');
    
    if ($pais === '' || $telefono === '' || $correo === '') {
        die("<script>alert('❌ Completa todos los campos'); window.history.back();</script>");
    }
    
    // Validate country exists in Paises table
    $resP = supabase_get('Paises?select=pais');
    $listaPaises = [];
    if (isset($resP['json']) && is_array($resP['json'])) {
        $listaPaises = array_column($resP['json'], 'pais');
    } else {
        $decodedP = json_decode($resP['body'], true);
        if (is_array($decodedP)) $listaPaises = array_column($decodedP, 'pais');
    }
    
    if (!in_array($pais, $listaPaises)) {
        die("<script>alert('❌ País no válido'); window.history.back();</script>");
    }
    
    $new = [
        'pais' => $pais,
        'telefono' => $telefono,
        'correo' => $correo,
        'created_at' => date('Y-m-d H:i:s')
    ];
    
    $res_insert = supabase_request('POST', $table_contactos, $new, ["Prefer: return=representation"]);
    $code = $res_insert['http'];
    $resp = $res_insert['body'];
    
    if ($code >= 200 && $code < 300) {
        echo "<script>alert('✅ Contacto creado correctamente'); window.location.href='contactos.php';</script>";
    } else {
        echo "<script>alert('❌ Error al crear contacto: $resp'); window.history.back();</script>";
    }
}

Country Validation

Contacts must specify a valid country from the Paises table:
contactos.php
// Fetch available countries
$paises = fetchFromSupabase('Paises?select=pais');

Countries Table

Table Name: Paises
ColumnTypeDescription
idintegerPrimary key
paistextCountry name
The system validates that the submitted country exists in the Paises table before accepting the contact.

Fetching Contacts

Contacts are retrieved with pagination:
contactos.php
$table_contactos = "contactos";

// Pagination
$page = intval($_GET['page'] ?? 1);
$perPage = intval($_GET['rowsPerPage'] ?? 10);
$offset = ($page - 1) * $perPage;

$path = "$table_contactos?select=*&order=created_at.desc&limit=$perPage&offset=$offset";
$contactos = fetchFromSupabase($path);

$totalPath = "$table_contactos?select=id";
$totalRecords = count(fetchFromSupabase($totalPath));
$totalPages = $perPage > 0 ? ceil($totalRecords / $perPage) : 1;

Pagination Configuration

  • Default rows per page: 10
  • Options: 5, 10, 20, 50
  • URL parameters: ?page=2&rowsPerPage=20

Contact Listing

Contacts are displayed in a table with:
  • Country: Contact’s country
  • Phone: Formatted phone number
  • Email: Email address (clickable mailto link)
  • Received: Submission date and time
  • Actions: Edit and delete buttons

Default Sorting

Contacts are sorted by creation date in descending order (newest first):
order=created_at.desc

Viewing Contact Details

Click on a contact row to view full details:
  • All contact information
  • Submission timestamp
  • Related inquiries (if tracked)
  • Follow-up history (if enabled)

Editing Contacts

1

Select Contact

Click the edit button next to the contact.
2

Modify Information

Update any of the fields:
  • Country
  • Phone number
  • Email address
3

Save Changes

Submit the form to update the database.

Deleting Contacts

Deleting a contact is permanent and cannot be undone.
To delete a contact:
  1. Click the delete button
  2. Confirm the deletion
  3. Contact record is permanently removed

Database Table

Table Name: contactos
ColumnTypeDescription
idintegerAuto-incrementing primary key
paistextCountry name
telefonotextPhone number
correotextEmail address
created_attimestamptzSubmission timestamp

API Endpoints

The Contacts module uses Supabase REST API:
  • GET /rest/v1/contactos - List all contacts
  • GET /rest/v1/contactos?select=*&order=created_at.desc&limit=10&offset=0 - Paginated contacts
  • POST /rest/v1/contactos - Create new contact
  • PATCH /rest/v1/contactos?id=eq.{id} - Update contact
  • DELETE /rest/v1/contactos?id=eq.{id} - Delete contact

Dashboard Integration

Contact statistics appear on the Dashboard:
dashboard.php
$total_contactos = get_count('contactos');
$ultimos_contactos = get_records('contactos');
  • Total contact count
  • Recent contact submissions (last 5)

Email Integration

Contact emails can be exported for email marketing campaigns:
Export contact emails to use with the Email Builder for newsletters and campaigns.

Best Practices

Timely Follow-up

Respond to new contacts within 24 hours

Data Privacy

Comply with GDPR and data protection regulations

Regular Review

Audit contacts monthly to remove duplicates

Categorization

Tag contacts by inquiry type for better organization

Troubleshooting

Invalid Country Error

Problem: “País no válido” error when creating contact Solution: The submitted country must exist in the Paises table. Check the countries dropdown or add the country to the Paises table first.

Missing Required Fields

Problem: “Completa todos los campos” error Solution: Ensure all three required fields (country, phone, email) are filled before submitting.

Duplicate Contacts

Problem: Same contact submitted multiple times Solution: Consider implementing duplicate detection based on email address. Add a unique constraint on the correo column:
ALTER TABLE contactos ADD CONSTRAINT unique_email UNIQUE (correo);

Form Integration

To integrate the contact form on your website:
<form action="/api/contactos.php" method="POST">
  <label>Country:
    <select name="pais" required>
      <!-- Populate from Paises table -->
    </select>
  </label>
  
  <label>Phone:
    <input type="tel" name="telefono" required>
  </label>
  
  <label>Email:
    <input type="email" name="correo" required>
  </label>
  
  <button type="submit" name="crearContacto">Submit</button>
</form>

Next Steps

Dashboard

View contact statistics

Email Builder

Send campaigns to contacts