Source Code for /public/appendix-samples/whats-your-name-2.php

<?php
// Check if we're provided a name and pronoun via GET params:
if( isset( $_GET['name'] ) && isset( $_GET['pronoun'] ) ) {
  // Strip any HTML from the name and pronoun:
  $name = htmlspecialchars( $_GET['name'] );
  $pronoun = htmlspecialchars( $_GET['pronoun'] );

  // If they selected "(no pronouns)", use their own name:
  if( $pronoun === 'NONE' ) {
    $pronoun = $name;
  }

  // Construct a greeting string:
  $greeting = "Today I met $name. I was so pleased to meet $pronoun!";
}
?>

<h1>
  Welcome to my friendly website!
</h1>

<?php if( isset( $greeting ) ) { /* We have a greeting! */ ?>

  <h2>
    <?php echo $greeting; ?>
  </h2>
  <p>
    I wonder who I will <a href="whats-your-name-2.php">meet next?</a>
  </p>

<?php } else { /* No greeting: show the form! */ ?>

  <p>
    Hi! Who are you?
  </p>
  <form method="get" action="whats-your-name-2.php">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" autofocus>
    <label for="pronoun">Pronouns:</label>
    <select id="pronoun" name="pronoun">
      <option value="them">they/them</option>
      <option value="him">he/him</option>
      <option value="her">she/her</option>
      <option value="it">it/its</option>
      <option value="aer">ae/aer</option>
      <option value="eir">ey/em/eir</option>
      <option value="faer">fae/faer</option>
      <option value="zir">ze/zir</option>
      <option value="hir">ze/hir</option>
      <option value="NONE">(no pronouns)</option>
    </select>
    <button type="submit">Hi!</button>
  </form>

<?php } ?>

<p>
  <a href="/source-viewer.php?file=public/appendix-samples/whats-your-name-2.php">View source code for this solution</a>
</p>