As the title suggest: Is it best practice to create HTML elements from inside external POST file or from within calling file?
Specifically, I am creating a wizard with PHP and jQuery. I am looking for help with fundamentals of structure when it comes to proper usage of passing data to an external page to process it.
The process goes as such: The user is on a page, "wizard.php". First, Step One is displayed, which asks them to enter a title of their Project in an input text element. A "Next" button is displayed as well.
Once this is done, the user clicks "Next", and a $(.post) method is invoked, and in an external file (wizard_process.php), the "title" is sanitized and added to the database.
Now, once the title has been sanitized, I want to display to them "Step Two", which is going to provide the Sanitized Title that they have input in the previous step, a few more input checkboxes (all inputs that are needed for Step Two), and other criteria for them to fill out.
Do I want to
a) print the HTML elements from within the "wizard_process.php" so that it is displayed on the parent, "wizard.php", page? (it would be a <h1>$sanitized_title</h1>
) along with the next set of checkboxes and inputs. It would include all elements of Step Two coded as HTML in the wizard_process.php.
b) send back json data (not in HTML form, but in json form) and only use the external php file (wizard_process.php) to sanitize and add to database and return json data. {sanitized_title: $sanitized_title} and then create the HTML element to display that data from within the calling jQuery function? (wizard.php)($(".successresponse").html(result);)
and then create the next set of checkboxes (Step Two inputs) from the calling page (wizard.php) as well?
Or do I want to
c) send back json data (not in HTML form, but in json form) and then make already created elements visible. For instance, having all the textboxes, questions, checkboxes, and drop downs from the entire wizard hard-coded into the HTML file, with the hidden option = true until we reach that phase of the wizard.
I know each of these is possible, but being a PHP coder, my first instinct would be to use the wizard_process.php as sort of a Controller/Model (MVC) so as to only process data, and not use it as the View. That means not actually creating the HTML elements inside that external post process file, but rather only return data to the calling function to then later format and display in HTML.
What would be the best way to handle this?