Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

list.html <!doctype html> <html lang=\"en\"> <head> <meta charset=\"utf-8\"> <ti

ID: 3914944 • Letter: L

Question

list.html
<!doctype html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>I Must Sort This Out!</title>
</head>
<body>
<!-- Script 7.6 - list.html -->
<div><p>Enter the words you want alphabetized with each individual word separated by a space:</p>

<form action="list.php" method="post">

   <input type="text" name="words" size="60">
   <input type="submit" name="submit" value="Alphabetize!">

</form>
</div>
</body>
</html>

list.php
<!doctype html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>I Have This Sorted Out</title>
</head>
<body>
<?php // Script 7.7 - list.php
/* This script receives a string in $_POST['words']. It then turns it into an array,
sorts the array alphabetically, and reprints it. */
// Address error management, if you want.
// Turn the incoming string into an array:
$words_array = explode(' ' , $_POST['words']);
// Sort the array:
sort($words_array);
// Turn the array back into a string:
$string_words = implode('<br>', $words_array);
// Print the results:
print "<p>An alphabetized version of your list is: <br>$string_words</p>";
?>
</body>
</html>

event.html
<!doctype html>
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>Add an Event</title>
</head>
<body>
<!-- Script 7.8 - event.html -->
<div><p>Use this form to add an event:</p>

<form action="event.php" method="post">

   <p>Event Name: <input type="text" name="name" size="30"></p>
   <p>Event Days:
   <input type="checkbox" name="days[]" value="Sunday"> Sun
   <input type="checkbox" name="days[]" value="Monday"> Mon
   <input type="checkbox" name="days[]" value="Tuesday"> Tue
   <input type="checkbox" name="days[]" value="Wednesday"> Wed
   <input type="checkbox" name="days[]" value="Thursday"> Thu
   <input type="checkbox" name="days[]" value="Friday"> Fri
   <input type="checkbox" name="days[]" value="Saturday"> Sat
   </p>
   <input type="submit" name="submit" value="Add the Event!">

</form>
</div>
</body>
</html>

event.php
<html lang="en">
<head>
   <meta charset="utf-8">
   <title>Add an Event</title>
</head>
<body>
<?php // Script 7.9 - event.php
/* This script handle the event form. */
// Address error management, if you want.
// Print the text:
print "<p>You want to add an event called <b>{$_POST['name']}</b> which takes place on: <br>";
// Print each weekday:
if (isset($_POST['days']) AND is_array($_POST['days'])) {
   foreach ($_POST['days'] as $day) {
       print "$day<br> ";
   }
} else {
   print 'Please select at least one weekday for this event!';
}
// Complete the paragraph:
print '</p>';
?>
</body>
</html>

Add validation conditions to both list.php and event.php that check for submitted form values before using them. Also, ensure that both forms accept string characters only. Attach all PHP files and any instructions that might be needed to test your work

Explanation / Answer

If you have any doubts, please give me comment...

list.php

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>I Have This Sorted Out</title>

</head>

<body>

<?php // Script 7.7 - list.php

/* This script receives a string in $_POST['words']. It then turns it into an array,

sorts the array alphabetically, and reprints it. */

// Address error management, if you want.

// Turn the incoming string into an array:

$ereg = '/^[a-zA-Z ]+$/';

if(preg_match($ereg, $_POST['words'])){

$words_array = explode(' ' , $_POST['words']);

// Sort the array:

sort($words_array);

// Turn the array back into a string:

$string_words = implode('<br>', $words_array);

// Print the results:

print "<p>An alphabetized version of your list is: <br>$string_words</p>";

}

else{

print "<p>Invalid string</p>";

}

?>

</body>

</html>

event.php

<html lang="en">

<head>

<meta charset="utf-8">

<title>Add an Event</title>

</head>

<body>

<?php // Script 7.9 - event.php

/* This script handle the event form. */

// Address error management, if you want.

// Print the text:

$ereg = '/^[a-zA-Z ]+$/';

if(preg_match($ereg, $_POST['name'])){

print "<p>You want to add an event called <b>{$_POST['name']}</b> which takes place on: <br>";

// Print each weekday:

if (isset($_POST['days']) AND is_array($_POST['days'])) {

foreach ($_POST['days'] as $day) {

print "$day<br> ";

}

} else {

print 'Please select at least one weekday for this event!';

}

// Complete the paragraph:

print '</p>';

}

else{

print "<p>Invalid name</p>";

}

?>

</body>

</html>