Skip to content

Commit

Permalink
update subscription form
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Nov 24, 2023
1 parent 700b6c3 commit b680bc0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/migrations/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ function migrate_all(): void {
migrate_0003();
migrate_0004();
}

migrate_all();
44 changes: 37 additions & 7 deletions src/templates/subscription/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

include dirname(__DIR__) . "/header.php";

$status = true;

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Retrieve form data
Expand All @@ -11,16 +13,26 @@
$phone = $_POST['phone'];

$subscription = null;

try {
$subscription = Subscription::subscribe_person(
$fullname, $email, $phone
);
} catch (Exception $e) {
print("<p>" . $e->getMessage() . "</p>");
echo '<p><a href="./form.php">Back to the form</a></p>';
$msg = $e->getMessage();
print("<p class='alert alert-danger'>" . $msg . "</p>");

$status = false;
$person = new Person($fullname, $email, $phone);
$subscription = new Subscription($person);

if ($msg == "Email could not be sent.") {
// exception of the exception
$status = true;
}
}

if ($subscription) {
if ($subscription && $status == true) {

Check failure on line 35 in src/templates/subscription/form.php

View workflow job for this annotation

GitHub Actions / build

Left side of && is always true.
?>

<h1>¡ CONFIRMAMOS TU PARTICIPACIÓN EN EL RETIRO!</h1>
Expand Down Expand Up @@ -155,20 +167,38 @@
}

// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if ($_SERVER['REQUEST_METHOD'] === 'GET' || $status == false) {
?>
<h1>Formulario de suscripción para personas que ya han pagado la tasa de registro</h1>

<div class="mt-5">
<form method="POST" action="">
<label for="fullname">Full Name:</label>
<input type="text" name="fullname" id="fullname" required><br><br>
<input
type="text"
name="fullname"
id="fullname"
required
value="<?php echo $subscription ? $subscription->person->fullname : ""; ?>"

Check failure on line 182 in src/templates/subscription/form.php

View workflow job for this annotation

GitHub Actions / build

Variable $subscription might not be defined.
/><br><br>

<label for="email">Email:</label>
<input type="email" name="email" id="email" required><br><br>
<input
type="email"
name="email"
id="email"
required
value="<?php echo $subscription ? $subscription->person->email : ""; ?>"
/><br><br>

<label for="phone">Phone:</label>
<input type="tel" name="phone" id="phone" required><br><br>
<input
type="tel"
name="phone"
id="phone"
required
value="<?php echo $subscription ? $subscription->person->phone : ""; ?>"
/><br><br>

<button type="submit" class="btn btn-primary">Save</button>
</form>
Expand Down

0 comments on commit b680bc0

Please sign in to comment.