|
||||||||||||
![]() ![]() Download ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Tutorial #2The World Talking Back...In this tutorial, we will cover the use of forms, getting information from the user, and processing that information. We will also see how to store information, send it out in the form of e-mail, and how to write simple procedures.
Hopefully by now, you've read the first tutorial and have some grasp as to using the environment, using the html command, and using variables and commands. You should take a look at the other variables available to you--after all, there are tons of stuff you can use! The pages we can write now are pretty much "self-contained." Wouldn't it be great if we could interact with the user? Well, we can--through the use of forms. Below is a simple form:
I'm sure that you've seen forms like this on the Internet. The code used to make the form looks like this:
Let's take a look each part of the form:
Once you submit a form, NeoWebScript takes care of all the details for you. Toward the beginning of your NeoWebScript snippet, simply call the command load_response, which pulls in any information available into an array called response. Remember the name=blah tags in the above example? Well, they're back--in the form of the "response" array. Let's make this more concrete. Let's say somebody filled out the above form, and we want to process what they said. Here's the code to do it:
Let's take another look at processing data received from forms. The basic idea is this:
*Note: Click HERE to go through the process of ordering once. After that, you will be able to better see how the form and form action methods work. Taking a closer look at processing forms Hopefully by now you've had a chance to look through the little music form above, and want to make something like it. Let's take a look at each of the steps involved:
Step 1 - Creating The FormThe first thing you need to do is determine exactly what information you want from the user, and what you want to do with it. For example, if you are asking for a person's name, a text input is probably the best bet. On the other hand, if you are asking for a mailing address, then maybe the textarea tag would be better suited, because addresses can not always be fit into pre-defined fields, and other countries do not always have the same addressing schemes as the United States. Remember: people could visit you page from anywhere in the world with the simple click of a mouse.Now that you have an idea of what type of information you want from the user, you need to find a way to get what they filled out into your action page. The action page is simply the reciever of the information. Using HTML form tags, you would specify something like this:
In this case, all of the information will be sent to "my_action_file.nhtml". The "method=post" tag simply says to send the information using a method that most modern browsers can understand. If you are concerned with older versions of software visiting your web page, you could try:
In either case, once you get your form setup the way you like it, you should save it as a text file, and make sure the extension is ".nhtml". Step 2 - Writing up the receiving endNow your form looks pretty, and you can fill it out and submit it, but--OOPS!-- fumble! The reciever wasn't there to catch your data. It looks like you'd better create the "my_action_file.nhtml" file.Getting "my_action_file.nhtml" to accept your data is pretty simple. All you have to do is insert the load_response tag somewhere in a NeoWebScript snippet, and the webserver will take care of the rest. Mind you--it doesn't do much right now, but we can address that in a little while. Take a look at the music example above, and see how the load_response command takes the data they entered and puts it into the response array. Remember our discussion of arrays in Tutorial 1? Well, it's no different here. The only difference is that the user provided the data, not us.
Well, you've got a working form, and you have a page that loads the values a user provides into an array. Let's see what that looks like up to this point:
Let's see what it would look like if we stored the information from our "musical" form into a simple database:
The best way to store information in a database is to store it under something unique to that entry. To do that, we choose a key that is unique. In the above example, we could store the record under the person's name, which would be pretty unique. That way, when we want to lookup what they sent us, we can just type use thier name to get our information. Let's pretend that the user filled in a form, and that one of the items in the form is a phone number. We decide to store the information based on that phone number:
Let's take a more indepth look at the dbfetch command:
With the information presented above, you should be able to handle some simple NeoWebScript code. In the first tutorial, we learned about getting to the outside world, emitting HTML, and using variables and commands. In this tutorial, we learned a bit about getting information from the user by means of forms. The will be future tutorials concerning logging, user tracking, and counters. Happy Scriptin' |
|||||||||||
Copyright © 1995-1999 NeoSoft Inc., 1770 St. James Place, Suite 500, Houston, TX 77056 USA. All Rights Reserved |