Hannes: Eingabe aus Formular in Datei schreiben

Beitrag lesen

Hi Hopsel

Hier der vorläufige Code von der "Schreib-Funktion" Eingabe wirts ja nicht brauchen.

<?php

echo "<font class="text">Vielen Dank f&uuml;r die Teilnahme an dieser Umfrage, Angaben wurden gespeichert.<br><br></font>";

Frage 1

$_daten['Politik'] = $_POST['Politik'];
  $_daten['Wirtschaft'] = $_POST['Wirtschaft'];
  $_daten['Sport'] = $_POST['Sport'];
  $_daten['Kultur'] = $_POST['Kultur'];
  $_daten['Gesellschaft'] = $_POST['Gesellschaft'];
  $_daten['Sonstige'] = $_POST['Sonstige'];

Frage 2

if(isset($_POST['sensationel'])
     and $_POST['sensationel'] >= 1
     and $_POST['sensationel'] <= 4)
  {
    $_daten['sensationel'] = $_POST['sensationel'];
  }
  else
  {
    $_daten['sensationel'] = 0;  ## oder auch = '';
  }

if(isset($_POST['einzigartig'])
     and $_POST['einzigartig'] >= 1
     and $_POST['einzigartig'] <= 4)
  {
    $_daten['einzigartig'] = $_POST['einzigartig'];
  }
  else
  {
    $_daten['einzigartig'] = 0;  ## oder auch = '';
  }

if(isset($_POST['sachverhalt'])
     and $_POST['sachverhalt'] >= 1
     and $_POST['sachverhalt'] <= 4)
  {
    $_daten['sachverhalt'] = $_POST['sachverhalt'];
  }
  else
  {
    $_daten['sachverhalt'] = 0;  ## oder auch = '';
  }

if(isset($_POST['auswirkung'])
     and $_POST['auswirkung'] >= 1
     and $_POST['auswirkung'] <= 4)
  {
    $_daten['auswirkung'] = $_POST['auswirkung'];
  }
  else
  {
    $_daten['auswirkung'] = 0;  ## oder auch = '';
  }

if(isset($_POST['ueberraschung'])
     and $_POST['ueberraschung'] >= 1
     and $_POST['ueberraschung'] <= 4)
  {
    $_daten['ueberraschung'] = $_POST['ueberraschung'];
  }
  else
  {
    $_daten['ueberraschung'] = 0;  ## oder auch = '';
  }

if(isset($_POST['prominenz'])
     and $_POST['prominenz'] >= 1
     and $_POST['prominenz'] <= 4)
  {
    $_daten['prominenz'] = $_POST['prominenz'];
  }
  else
  {
    $_daten['prominenz'] = 0;  ## oder auch = '';
  }

if(isset($_POST['beteiligung'])
     and $_POST['beteiligung'] >= 1
     and $_POST['beteiligung'] <= 4)
  {
    $_daten['beteiligung'] = $_POST['beteiligung'];
  }
  else
  {
    $_daten['beteiligung'] = 0;  ## oder auch = '';
  }

if(isset($_POST['reichweite'])
     and $_POST['reichweite'] >= 1
     and $_POST['reichweite'] <= 4)
  {
    $_daten['reichweite'] = $_POST['reichweite'];
  }
  else
  {
    $_daten['reichweite'] = 0;  ## oder auch = '';
  }

if(isset($_POST['dauer'])
     and $_POST['dauer'] >= 1
     and $_POST['dauer'] <= 4)
  {
    $_daten['dauer'] = $_POST['dauer'];
  }
  else
  {
    $_daten['dauer'] = 0;  ## oder auch = '';
  }

if(isset($_POST['bedeutung'])
     and $_POST['bedeutung'] >= 1
     and $_POST['bedeutung'] <= 4)
  {
    $_daten['bedeutung'] = $_POST['bedeutung'];
  }
  else
  {
    $_daten['bedeutung'] = 0;  ## oder auch = '';
  }

if(isset($_POST['einfach'])
     and $_POST['einfach'] >= 1
     and $_POST['einfach'] <= 4)
  {
    $_daten['einfach'] = $_POST['einfach'];
  }
  else
  {
    $_daten['einfach'] = 0;  ## oder auch = '';
  }

if(isset($_POST['identifikation'])
     and $_POST['identifikation'] >= 1
     and $_POST['identifikation'] <= 4)
  {
    $_daten['identifikation'] = $_POST['identifikation'];
  }
  else
  {
    $_daten['identifikation'] = 0;  ## oder auch = '';
  }

if(isset($_POST['sonstige'])
     and $_POST['sonstige'] >= 1
     and $_POST['sonstige'] <= 4)
  {
    $_daten['sonstige'] = $_POST['sonstige'];
  }
  else
  {
    $_daten['sonstige'] = 0;  ## oder auch = '';
  }

Frage 3

if(isset($_POST['3'])
     and $_POST['3'] >= 1
     and $_POST['3'] <= 3)
  {
    $_daten['3'] = $_POST['3'];
  }
  else
  {
    $_daten['3'] = 0;  ## oder auch = '';
  }

Frage 4

if(isset($_POST['4'])
     and $_POST['4'] >= 1
     and $_POST['4'] <= 2)
  {
    $_daten['4'] = $_POST['4'];
  }
  else
  {
    $_daten['4'] = 0;  ## oder auch = '';
  }

Frage 5

if(isset($_POST['5'])
     and $_POST['5'] >= 1
     and $_POST['5'] <= 3)
  {
    $_daten['5'] = $_POST['5'];
  }
  else
  {
    $_daten['5'] = 0;  ## oder auch = '';
  }

Frage 6

if(isset($_POST['6'])
     and $_POST['6'] >= 1
     and $_POST['6'] <= 3)
  {
    $_daten['6'] = $_POST['6'];
  }
  else
  {
    $_daten['6'] = 0;  ## oder auch = '';
  }

Frage 7

$_daten['7'] = $_POST['7'];

Frage 8

$_daten['8'] = $_POST['8'];

Frage 9

if(isset($_POST['9'])
     and $_POST['9'] >= 1
     and $_POST['9'] <= 4)
  {
    $_daten['9'] = $_POST['9'];
  }
  else
  {
    $_daten['9'] = 0;  ## oder auch = '';
  }

Frage 10

if(isset($_POST['10'])
     and $_POST['10'] >= 1
     and $_POST['10'] <= 4)
  {
    $_daten['10'] = $_POST['10'];
  }
  else
  {
    $_daten['10'] = 0;  ## oder auch = '';
  }

Frage 11

if(isset($_POST['11'])
     and $_POST['11'] >= 1
     and $_POST['11'] <= 4)
  {
    $_daten['11'] = $_POST['11'];
  }
  else
  {
    $_daten['11'] = 0;  ## oder auch = '';
  }

Frage 12

if(isset($_POST['12'])
     and $_POST['12'] >= 1
     and $_POST['12'] <= 3)
  {
    $_daten['12'] = $_POST['12'];
  }
  else
  {
    $_daten['12'] = 0;  ## oder auch = '';
  }

Frage 13

if(isset($_POST['13'])
     and $_POST['13'] >= 1
     and $_POST['13'] <= 2)
  {
    $_daten['13'] = $_POST['13'];
  }
  else
  {
    $_daten['13'] = 0;  ## oder auch = '';
  }

Ende Fragebogen

$delim = '"';
$sep   = ';';
$CRLF  = chr(13).chr(10);

function array_mask($_array,$mask)
{
  if (is_array($_array))
  {
    foreach($_array as $key => $val)
    {
      array_mask($_array[$key],$mask);
    }
  }
  else
  {
    str_replace($delim,$delim.$delim,$_array);
   str_replace($mask,$mask.$mask,$_array);
  }
  return $_array;
}

$_daten = array_mask($_daten,$delim);

$record_str = $delim.implode($delim.$sep.$delim , $_daten).$delim.$CRLF;

echo '<p>'.htmlentities($record,ENT_QUOTES)."</p>\n";

$fh = fopen('umfrage.csv','ab+');

fwrite($fh, $record);

fclose($fh);

?>

vg
Jo