Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Define checkWord() here:
- function checkWord($input, $letter){
- if ($_SERVER["REQUEST_METHOD"] === "POST" && strtolower($input[0]) != $letter){ //also to check same letter despite whether upper or lower case
- return "* This word must start with the letter $letter!";
- }
- else {
- return "";
- }
- }
- ?>
- <h1>Time to Practice our ABCs</h1>
- <form method="post" action="">
- Enter a word that starts with the letter "a":
- <br>
- <!-- Assign the value attribute of each input tag to the value submitted by a user. User should be able to see what they entered in input field once they submit their form. -->
- <input type="text" name="a-word" id="a-word" value= "<?= $_POST["a-word"]; ?>">
- <br>
- <!-- Invoke the function here to pass user's input into function for checking -->
- <p class="error" id="a-error"><?= checkWord($_POST["a-word"], "a"); ?></p>
- <br>
- Enter a word that starts with the letter "b":
- <br>
- <input type="text" id="b-word" name="b-word" value= "<?= $_POST["b-word"]; ?>">
- <br>
- <p class="error" id="b-error"><?= checkWord($_POST["b-word"], "b"); ?></p>
- <br>
- Enter a word that starts with the letter "c":
- <br>
- <input type="text" id="c-word" name="c-word" value= "<?= $_POST["c-word"]; ?>">
- <br>
- <p class="error" id="c-error"><?= checkWord($_POST["c-word"], "c"); ?></p>
- <br>
- <input type="submit" value="Submit Words">
- </form>
- <div>
- <h3>"a" is for: <?= $_POST["a-word"];?><h3> <!-- What user entered can be seen here -->
- <h3>"b" is for: <?= $_POST["b-word"];?><h3>
- <h3>"c" is for: <?= $_POST["c-word"];?><h3>
- <div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement