6.3. Modifying admin.php to Save Page Associations

Saving the page an entry is associated with is as easy as adding another input to your form. However, there are a couple reasons you don't want to require the user to fill out the page an entry belongs on. First, it's inconvenient for the user; second, it increases the risk of typos or confusion.

Fortunately, HTML forms allow you to insert hidden inputs, which contain a value that is passed in the $_POST superglobal, but isn't displayed to the user. In your admin.php script (full path: /xampp/htdocs/simple_blog/admin.php), add a hidden input to your form by inserting the lines in bold:

<?php
if(isset($_GET['page']))
{
    $page = htmlentities(strip_tags($_GET['page']));
}
else
{
    $page = 'blog'; ...

Get PHP for Absolute Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.