Jump to content

Making survey with form checkbox using php


hahn

Recommended Posts

Hi all,

 

I'm a noob in the world of php. :) Wonder if anybody here can help me with what I'm working on.

What I'm trying to do here is to make a survey using checkbox and php and save the result into a text file.

 

The survey is made of 5 pages, each containing multiple checkboxes and submit button.

The structure for all 5 pages all exactly the same.

 

So the expected user topography is like this.

 

In page1.html,

when user checks all that has to be checked and click submit,

the page saves the result into a text file through PHP and redirect user to the page2.html

 

In page2.html to page4.html

exactly the same pattern goes here.

 

When all the survey is complete page4 leads users to page5.html that gives the user "thank you message"

 

Simple.

 

So what I've tried to achive this is like this;

 

page1.html here:

<form onsubmit="window.open ('page2.html')" id="form1" name="form1" method="post" action="chi.php">
<input type="checkbox" name="chi[]" id="0" value="SYS" />
<input type="checkbox" name="chi[]" id="1" value="IMT" />
<input type="checkbox" name="chi[]" id="2" value="GOO" />
<input type="checkbox" name="chi[]" id="4" value="LEC" />
<input type="checkbox" name="chi[]" id="5" value="TRC" />
<input type="submit" name="submit" id="submit" value="Continue" />

 

1. I'm using onsubmit="window.open ('[next_page.html]') here but wonder is there any better way to do the same job as it opens a new tab instead of printing the next page in the same tab.

 

chi.php here:

<?php
$file = "chi.txt"
if (isset($_POST)) {
$fp = fopen($file, "a") or die("Couldn't open $file for login!");
$array = $_POST["chi"];
for ($i = 0; $i < count($array); $i++) {
	fwrite($fp, "$array[$i]\n\r");
}
fclose($fp);
} else {
echo("No choice made.");
}
?>

 

The result I'm expecting from this code is like this;

 

chi.txt

SYS
IMT
GOO
LEC
LEC
GOO
...
...

 

I'll sort it up with excel later on.

 

But for some reason it returns no result.

Please help me finding out what's wrong on the both of codes above or suggest me with the better solution.

 

Ciao! :)

 

Han

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.