About the app
Wow. Lots going on here!
For your convenience, we have linked code snippet code blocks to this explanation so you can see for yourself how things were done. Because they are more involved, we linked to them as text files rather than integrating them into the fabric of this page. It's not as nice but it was easier under the circumstances.
The Various 'Moving Parts:'
- The submission form was created in a separate file to keep the congestion of this page a bit lower. It's easier to maintain/edit something if it's in its own file and not risk other elements getting disrupted during the process.
- Note the action attribute with it's PHP command about $_SERVER["PHP_SELF]. It's what makes this page 'self-referential'. When the form loads, the server copies the location of this very file into the action value and voila! The page loads itself!
- Because we are lazy, we 'prepopulated' the form with bogus 'default' entries so we didn't have to type out a bunch of stuff to see the form in action. Note how we used PHP to 'echo' those entries into the form. The default values were supplied by PHP variables before the page loaded, in a 'cave of wonders' placed above the DOCTYPE. That block of code also hosted a function that can make a numeric selection block in the form, which we used.
- There are several 'buttons' on the page but their natures (types) are different. 'input' HTML widgets of type submit are used with PHP in cahoots with the name attribute for putting information in either the GET or POST super-global arrays. Input widgets of type button to not activate form actions but can be used with JavaScript to do tricks like clearing or reseting the form. You can view those functions here. They are pretty snazzy: you should look at them closely.
- Take note that the buttoms themselves are elements of data that are provided as well. It is their name that we can use to see if a form has been submitted, and therefore in need of being processed.
- By supplying the single-word attribute required we can (sort of) force a user to supply values to elements we must have.See what happens if you try to submit the form without information provided in a field designated with an asterik (*).
- Placeholder attributes are there to show examples of how the data should be provided. If the form is cleared, you see those placeholders: they disappear when you start completing it.
- The PHP block before the page loads captures information from the POST array and stores it in PHP variables.
- If the form has not been submitted, the POST attribute (submit) has not been set. The isset function keeps track of this. If it finds the value in itself, it knows it can find other goodies from the form as well.
- It's easiest (but not required) if you make sure the PHP variable (with a $ by the way) is the same as the 'name attribute' in the POST array.
- Note: don't use $ when referencing the 'name' attribute information from the form in the $_POST[] code block.
- It is VERY COMMON to have a if or if/else block of code hinging on whether or not a 'submit' attribute has been 'set.' This same footprint is typically found in the body of the webpage where we make decisions on whether someone sent the information or not.
- In the body of the webpage, we find the familiar if/else block footprint that hinges on the 'isset' nature of the 'submit' attribute. If the form's been submitted, we created a table, on the fly, populated with the information we sent; if not, we show the form requesting information. If the information has been supplied, why show the form again? When you run the app, you will see the form disappear and the table appear!
It's PHP magic! Thank you, PHP genie!
01/14/20