Multiple forms with PHP
Two weeks ago I showed you how using a little Javascript
and SSI (Server Side Includes) you could create dynamic
forms. This week I'd like to show you a little tip on how
you can use PHP to pass variables to the next page, without
having to learn any special programming skills.
PHP is a programming language that is embedded in the page
with the HTML. It's a language loosely based on C with some
variations similar to Perl. Many Unix flavored servers are
supporting it, by installing it for their customers use.
Typically it is used for interacting with databases like
mySQL, without the need of using things like ODBC or DBI and
DBD.
While the coding for this can be quite complicated, it
doesn't mean that you have to be a programmer to get some
value out of working with PHP. The benefits of using PHP is
that it is a server side scripting language rather than
client side, like Javascript, so it is not limited to any
specific browser.
Using a little bit of PHP you can transfer information
between as many pages as you wish. I'm going to give you an
example of it in action. This is a new sales piece I am
working on and it isn't finished. I don't even know if I am
going to use it...but since it is already on the web it will
work as an example.
The example starts here:
(Example has been removed)
You won't be able to see the actual PHP code, because the
server parses it before it is sent to the browser, but I
will show you here how it is done and explain enough of it
so you can do it yourself.
PHP saves the information contained in the NAME attribute of
a form element as a variable for you. Using "hidden" form
fields you can easily include it in the next pages.
The first form fields you see on the "action.php3" page are
all drop down lists: The only things to note here is the
FORM ACTION:
<form action="action2.php3" method="POST">
...which calls the next page. There isn't ant special coding
on this page. Because of the ".php3" extension, the form is
parsed on the server so that all of the NAME values in the
form elements are being save for us as variables. The next
page "action2.php3" calls the variables like this:
<form action="action3.php3" method="POST">
<input type=hidden name="POP" value="<? echo $POP ?>">
<input type=hidden name="autoresponders" value="<? echo $autoresponders ?>">
<input type=hidden name="lists" value="<? echo $lists ?>">
<input type=hidden name="aliases" value="<? echo $aliases ?>">
Also note the list that reads what the users choices
were and reads them back to him:
<UL TYPE="circle">
<LI><?php echo $POP?>
<LI><?php echo $autoresponders?>
<LI><?php echo $lists?>
<LI><?php echo $aliases?>
</UL>
Continuing on in this fashion, we can have lots more sales
info, lots more pages, sparsely populated with a form. This
saves the user from having to make a whole lot of decisions
on ONE order page. We just add to the hidden variables for
each following page. The last page I have coded so far
contains this which is what has been picked up by the other
pages along the way:
<form action="action5.php3" method="POST">
<input type=hidden name="POP" value="<? echo $POP ?>">
<input type=hidden name="autoresponders" value="<? echo $autoresponders ?>">
<input type=hidden name="lists" value="<? echo $lists ?>">
<input type=hidden name="aliases" value="<? echo $aliases ?>">
<input type=hidden name="controlpanel" value="<? echo $controlpanel ?>">
<INPUT TYPE="HIDDEN" NAME="comments">
Also note, on the last page I have coded so far, the
information the user has submitted is displayed to him/her
so they can review it.
What I will likely do at the end is have another page that
collects an e-mail address and name, sends an autoresponse
message, and the data to me to follow-up on. The final form
will be processed with a CGI script and this data imported
into that form using PHP. The same thing could be done but
written to a flatfile database one could import into their
own local database.
What do you think? Pretty simple trick?
| Back to Article Index |
Copyright © All Rights Reserved. The information/images on this website
may not be reproduced or republished by anyone without permission.