When a visitor views a page from your website the server sends the data normally xterm Al to the user's
web browser.
In order to receive data from the user we need to use a farm in our 8 p.m. owl where the farm the user
can enter data and send it from the browser to the server.
Once we've got the data on the server we can process it using P2P.
To add a farm to a Web page we use the farm element inside the farm elements.
We place controls which can be text boxes buttons and so on.
Let's look at an example.
Let's create a new page and call it farmed up here p.
Now add some basic t l for the head and body and so on in the body of the aced him out.
Let's add a farm.
And inside this farm Let's add a couple of controls.
First an input followed by a button.
We'll learn more about these elements in a moment.
Next let's create another page and call it process from P Es P.
We'll leave this blank for now.
Back in the farm script we'll add an action attribute to the farm element that contains the name of
the script.
We just added.
If we look at farmed up p HP in a browser we see a text box and a button we can enter text into the
box and click the button.
This is known as submitting a farm.
If we look at the address bar we can see it's changed to process farmed up HP.
We left this file blank which is why we don't see anything in the main browser window.
However in addition to the address of the script file We've also got a value in the query string.
This is the value that we just typed into the text box in the farm.
We learnt earlier that we can access the query string using the get array.
So in here let's just dump out the entire array like that.
Back in the browser.
If we try that again.
Enter a value in the text box and press the button to submit the farm.
We can see the value that we typed into the text box.
So using this array we can access the data that was entered into the farm.
When you submit a farm it's like clicking on a link to the page specified in the action attribute.
However in addition to requesting this page any data typed into the farm is sent along with it.
Let's try something else.
What will happen if we remove the action attribute.
Like this.
In the browser.
Now when we submit the farm
we see the farm again.
However if you notice the address bar the page is the same but the data is still in the query string.
If you dont specify an action for a farm its submitted to itself.
So when this farm is submitted its data is sent to this page from HP.
The web server then sends this page back to the browser as the farm is being submitted to itself.
Its like the page has been requested again in the browser.
Only this time the farm has sent its data in the query string.
So when we first visit the page the query string is empty.
When we supply a value and submit the farm the page is loaded again and the data from the farm is available
in the query string.
Let's add some cold up here at the top.
To print out the get array.
In the browser we see an empty array.
That's because there's nothing in the query string.
If we enter a value in the form
and submit the farm we see the form again but we also see what's in the get array processing farm in
the same script like this is a quite common technique used when you want to redisplay a farm so a user
can correct errors are supply required fields that they might have missed out and so on.
We'll look at this in more detail later on.