Panafrikan PHP

An educational initiative by EColSi

Discover EColSi
Choose your language
Explore the course

B08 — Listen to the user with GET and POST forms

Basic level · Lesson B08

B08 — Listen to the user with GET and POST forms

B08 — Listen to the user with GET and POST forms

Result: form that calculates a weekly plan.
Core concept: a request carries data; receiving them does not mean trusting them.
Guideline time: 90–120 minutes.

How do you pass a form response to PHP?

Each field with attribute name travels in a request. GET is useful for shareable queries; POST to send data that should not be in the URL, although by itself it does not encrypt or validate.

Previous connection

In B07 we filter data defined in code. Now the selected level will come from a form.

Guided laboratory

<?php
$hours = $_POST['hours'] ?? '';
?>
<form method="post">
  <label>Horas disponibles
    <input name="hours" type="number" min="1" max="40" value="<?php echo htmlspecialchars((string) $hours); ?>">
  </label>
  <button>Crear plan</button>
</form>

<?php if ($hours !== ''): ?>
  <p>Recibimos <?php echo htmlspecialchars((string) $hours); ?> horas.</p>
<?php endif; ?>

The HTML attribute helps the experience, but the actual server validation will arrive in B09.

Medium Mission

Create a form with topic, level and hours. Preserves values ​​after sending and displays a summary.

University Extension

Implement a GET version for filters and a POST version to create a plan. Explains idempotence initially and why sensitive data should not appear in URLs or code.

Tests

First load, completed form, empty field, limit values and manipulated text from the request.

Delivery

Includes code, URL or request capture and difference between GET and POST. SEND TO TUTOR.

Next: B09 — Validation.

Comments

Popular posts from this blog

Bem-vindo ao Panafrikan PHP: aprenda, construa e compartilhe

Bienvenue sur Panafrikan PHP : apprenez, créez et partagez