Forum Moderators: mack

Message Too Old, No Replies

Best way to set up multiple forms on one site

(and the best way to maintain the data)

         

Herb75

8:33 pm on Aug 10, 2005 (gmt 0)

10+ Year Member



I want to be able to set up multiple contact / customer information forms on one site (specific to different fields of interest) and was wondering what is the best way to create the forms and to maintain all the information that is collected.

Ideally I would like to have the information sent to the appropriate database/server log as well as get an email notification when a form is completed.

any help is appreciated.

-Herb

mack

2:15 am on Aug 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You could do this all with one form. But pass a variable to is using php or any scripting language that you are used to working with.

For example you could send users from your sales page to the form using a url like this...

example.com/feedback/form.php?area=sales

The form could then decide what fields to display to users based on what variable you passed to the script. You could then write the results to a database incuding the area they where refered from. e.g. sales.

Hope this helps.

Mack.

Herb75

6:57 pm on Aug 11, 2005 (gmt 0)

10+ Year Member



I'm not used to any paticular scripting language (it's all new to me). What would be the most effecient way to go that allows for modifications in the future?

And is there anywhere online that I could read about this (that isnt too technical)?

thanks for your help!

mack

7:50 pm on Aug 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I would be tempted to go with php.

code like the following should work...


<form method="get" action="http://www.example.com/feed-back.php">
<?php
if ($area == 'sales'){
place form here for sales feedback form.
}else
if ($area == 'about'){
place form here for about feedback form.
}else{
place form here for general feedback form.
</form>
?>

the above code will present the correct form depending on what area they are send to. If this code was on www.example.com/form.php we would send it to www.example.com/form.php?area=sales to display the sales feedback form.

The form then needs to send it's data to another script to write the information to mysql.


<?php
$link = mysql_connect(localhost, DBuser, DB password);
$db = mysql_select_db(DBname, $link);

$query = "INSERT INTO Your Table (value1, value2, value3, value4, value5, value6) VALUES ('$calue1', '$value2', '$value3', '$value4', '$value5', '$value6')";
$result = mysql_query($query, $link);

echo "Thank you very much for contacting us.";
?>

The values would be specified within your form fields.

Hope this gives you some ideas.

Mack.

[edited code.]

[edited by: mack at 11:43 pm (utc) on Aug. 15, 2005]

shazukura

10:40 pm on Aug 15, 2005 (gmt 0)

10+ Year Member



Not to nitpik, but you'll get in trouble with PHP if you try that:

<?php
if ($var = 'val') {-do something-;}
?>

I know because it's a mistake I make all the time. The above code would set the value of $var to 'val'. You need *two* equal signs to do the 'is equal' operation, a single equal sign just assigns the value. So... what you'd want to be sure you do is:

<?php if ($var == 'val') {-do something-;}?>

with two equal signs and no spaces :)

mack

11:41 pm on Aug 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



shazukura spot on, well noticed.

I have edited the above code.

Thanks.

Herb75

12:03 am on Aug 16, 2005 (gmt 0)

10+ Year Member



thanks for the help!