A client of mine asked me if i can find a solution for this problem.
His website (still a WIP) http://welkommagazine.nl/luuk/ has a form. The form obviously uses a sendmail script to send the form to e-mail. From thereon he manually copy/pastes all the submissions to excel.
What he wants is that the forms online automaticcaly are added to an excel document to save him a lot of work.
Now i am not a programmer, but a designer.. I think this can be done, but i have absolutely no clue how. I googled alot for it and the only thing i found was a dreamweaverplugin.
Is there a way to do this, if so, how?
Found the answer myself. I wrote a PHP code snippet which actually stores the fields comma seperated in a CSV file and sends an email to a desired adress with the filled in fields.
if(isset($_POST['Submit'])){ $pakket = $_POST['pakket']; $extragidsen = $_POST['extragidsen']; $naambedrijf = $_POST['naambedrijf']; $err = ''; if(trim($pakket)==''){ $err .= '-Please enter a name'; } if(empty($extragidsen)){ $err .= '-Please enter an email address'; } if(strlen($naambedrijf)==0){ $err .= '-Please enter a comment
'; } if($err!=''){ echo $err; } else{ $filename = 'file.csv'; $somecontent = $pakket . ',' . $extragidsen . ',' . $naambedrijf . "\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'Inschrijving welkom'; // Your email address. This is where the form information will be sent. $emailadd = 'luuk@luukratief.com'; // Where to redirect after form is processed. $url = 'http://www.google.com'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // --------------------------Do not edit below this line-------------------------- $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i '; fclose($handle); } else { echo "The file $filename is not writable"; } } }
Maybe the code aint that clean as it can be, but eh it works.
Feel free to clean up the code if you want to 🙂
I guessed I would answer this myself for the community…
BTW u need to set “write” rights to “file.csv”
cheers