Source Code for /public/appendix-samples/whats-your-name-2.php
<?php
if( isset( $_GET['name'] ) && isset( $_GET['pronoun'] ) ) {
$name = htmlspecialchars( $_GET['name'] );
$pronoun = htmlspecialchars( $_GET['pronoun'] );
if( $pronoun === 'NONE' ) {
$pronoun = $name;
}
$greeting = "Today I met $name. I was so pleased to meet $pronoun!";
}
?>
<h1>
Welcome to my friendly website!
</h1>
<?php if( isset( $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 { ?>
<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>