What we will do is allow a user to pass an array of element "names" that they want to be hidden. Some examples might be "firstName", "lastname", "email", or "username". Our PHP class will return these elements as hidden input elements, and then store them into a session variable. After the form is submitted, the class will check all of these elements to see if any are filled. If any are filled, we know something has happened. So... let's begin.
First, we need to build our PHP class. Here's the barebones...
<?php
class safeForm {
//This variable will store the current data.
private $data = array();
//This variable will store the old data to be checked.
private $old_data = array();
//This function will actually do the input element creation.
function setFields($fieldNames) {
}
}
What you see are our two variables, one to store our current data, and one to store the old data. Our function setFields() will actually do the creation of our hidden elements. The variable $fieldNames will be an array of string elements of the field names to hide.