OK. First, thanks a lot. It looks to me like the only part of the HtMLmthe PHP refers to is the method of the form, right? Meaning, I don’t have to name any HTML certain things?
If you type something into the form field named “field1A” and your form conforms to the basic html rules, then that variable is available to the place you post the form to (in this case itself) as part of the POST array which you access with
echo $_POST['field1A'];
You should now make a form which features more sensible variable names in order that when the form is posted back to itself you can do the equivalent of:
// if POST isset etc
echo "Hello there, ". $_POST['first_name'] . " " . $_POST['last_name'] ;
The line below just tells the html to post data back to the server, using the script “process_form.php”.
<form action="process_form.php" method ="POST">
This line tells it to post the value of this input control as a variable named field1A.
<input type="text" name="field1A" />
This line, in “process_form.php”, is used to get the field value, so you can do stuff with it.
$field1A = $_POST['field1A'];
The sample code previously given was offered as simple demo of an html form that posts back to itself. The php block at the top just detects if anything was previously posted, and if so, shows it, followed by an <hr /> to separate it from the form display.
Presumably, though, you want this info stored somewhere for later use? At the moment, the info will be lost once the page is closed.
If you want to store the information for display later, then this is where a CMS is handy. You might need to clarify what you are trying to do to get the answers you need.
The action attribute refers to the server side procesing script you want to send the form data to. It could be to another page from the page containing the form. eg <form action=“formProcessor.php” … or it could be to the page containing the form eg <form action=“#”…
form data is sent as name/value pairs for each of the form’s input controls…eg <input type=“text” name=“txtUsername”… or <input type=“checkbox” name=“chkCountry” value=“france”…The entered username is sent as the name txtUsername and if the user checks the checkbox, the string france is sent as the name chkCountry.
The method attribute determines how the form data is sent to your server side script. It can be set to POST or GET. If it is set as a GET then all your form data is appended to the url the action attribute is set to as name value pairs…eg…formProcessor.php?txtUsername=fred&chkCountry=france…and the sent form data can be got in formProcessor.php in $_GET[‘txtUsername’] etc…If method is set to POST then all the form data is sent via the headers in formProcessor.php and the form data can then be got in formProcessor.php with $_POST[‘txtUsername’] etc. Usually you use GET if you want to give your users the opportunity to bookmark database driven web pages. Otherwise you would normally use POST.
You don’t need a CMS to store form data. This looks like a homework or self teaching type exercise, so a CMS is gross overkill if that is the case. You can store the form data is just a plain text file or write a few lines of basic code to store it in a database.