View Single Post
  #4 (permalink)  
Old 28-04-2009, 11:02 AM
viaterra viaterra is offline
Member
 
Join Date: Apr 2009
Posts: 29
Thanks: 0
Thanked 6 Times in 4 Posts
Default "your opinion" sidebox

Here's how I did it in 5 steps :

1- install a blank additional sidebox
http://www.zen-cart.com/index.php?ma...roducts_id=174

2- customize and add the following content to define_editable_sidebox_content.php
(or whatever you renamed it to)

<script type="text/javascript">
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}
</script>
<!-------------begin form------------>
<div style="text-align: center;">
<FORM ACTION="http://<yourdomain.com/path>/surveyform.php" METHOD="POST" NAME="survey">
<select name="navigation" size="1" id="navigation" style="width:130px; color: #a9d8fa; background-color: #0e4b8d;">
<option value="">navigation :</option>
<option>1 - super easy</option>
<option>2 - no problem</option>
<option>3 - fonts too small</option>
<option>4 - too cluttered</option>
<option>5 - confusing</option>
</select><br>
<select name="colours" size="1" id="colours" style="width:130px; color: #a9d8fa; background-color: #0e4b8d;">
<option value="">colours :</option>
<option>1 - really cool</option>
<option>2 - just fine</option>
<option>3 - nothing special</option>
<option>4 - too dark</option>
<option>5 - blue is no good</option>
</select><br>
<select name="products" size="1" id="products" style="width:130px; color: #a9d8fa; background-color: #0e4b8d;">
<option value="">products :</option>
<option>1 - good choice & prices</option>
<option>2 - not enough options</option>
<option>3 - too many options</option>
<option>4 - too expensive</option>
<option>5 - not what I want</option>
</select><br>
<input type="text" style="width:125px; height:14px; background: #AFD3E0;" value="write suggestions" name="comments" id="comments "maxlength="50" onfocus="clearText(this);"><br>
<input type="submit" value="Submit" name="Submit" style="border: 2px outset #d7b9c9; background: #AFD3E0;" title="Only 1 submission allowed per visitor. Please use the contact form if you need to write more.">

</FORM>
</div>
<!-------------end form------------>


3- Create a database (refer to instructions of your hosting service) and name it storesurvey. In this database, create a table called user_data. Create the fields : customer_id, user_agent, navigation, colours, products, comments, date. Set the field customer_id to primary (that means the value, here the IP address, must be unique, and it prevents the same customer using the form more than once). All fields are type varchar except date which is ... date

4- create and save the file<yourdomain.com/path>/surveyform.php with the following content

<?php
$con = mysql_connect("localhost","DB_username","DB_passwo rd"); //MySQL DB Username and Password as defined when creating the DB
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("storesurvey", $con); //Replace with your MySQL DB Name
$ip = $_SERVER['REMOTE_ADDR'];
$agent = $_SERVER['HTTP_USER_AGENT'];
$navigation=mysql_real_escape_string($_POST['navigation']);
$colours=mysql_real_escape_string($_POST['colours']);
$products=mysql_real_escape_string($_POST['products']);
$comments=mysql_real_escape_string($_POST['comments']);
$timeStamp=date("y.m.d");
$sql="INSERT INTO user_data (customer_id,user_agent,navigation,colours,product s,comments,date) VALUES ('$ip','$agent','$navigation','$colours','$product s','$comments','$timeStamp')"; //user_data is the name of the MySQL table where the form data will be saved.

if (!mysql_query($sql,$con)) {
// die('Error: ' . mysql_error());
die(header("Location: index.php"));
}
// the 3 lines above define what happens when there's an error, such as when a user submits twice the form, in this case, simply reload the homepage. You could also customize an error page.
mysql_close($con);
header("Location: index.php?main_page=contact_us&action=success");
// this line sends the user to the default "thank you for your submission" page
?>


5- test your form. While testing you may want to swap commented lines
die('Error: ' . mysql_error());
// die(header("Location: index.php"));
so that you can spot the error if any.


I know it's very "manual" procedure and anyone with a better knowledge of SQL could easily write a script to create the DB. One could also make a Zen Cart module, but there's so much customizing according to each store owner's needs that I am not sure it would be easy to make something generic enough. Let me know if you encounter any problem (note that I won't be able to help with queries related to DB creation since that depends on your hosting service).

Denis

Useful resources :
http://dev.mysql.com/doc/
http://es2.php.net/
your own hosting service help files
Reply With Quote
The Following 3 Users Say Thank You to viaterra For This Useful Post:
dezina (28-04-2009), Dippy (28-04-2009), pupsandpets (28-04-2009)