Hoe verstuur ik onderstaand forumulier nou naar een e-mailadres?






<<<<<< start of index.php >>>>>>

<?php


include "array.php";

// everything between these {} will be done when the form is submitted

if ($action == "sent")

{

// $options is the array that contains all the questions and their specifics. It's located in array.php

foreach ($options AS $number => $array)

{

if($array[type] == "radio" && $array[required] == "yes")

{

// this means none of the radiobuttons for this question have been checked

if(!$radio[$number])

{

$error[$number] = "<tr>\n<td colspan=\"3\">\n\t<font color=\"red\">You forgot to answer this question!</font>\n </td>\n</tr>\n";

}

}

if($array[type] == "check" && $array[required] == "yes")

{

// this means none of the checkboxes for this question have been checked

if (!$checkbox[$number])

{

$error[$number] = "<tr>\n<td colspan=\"3\">\n\t<font color=\"red\">You have to at least answer one of these options</font>\n </td>\n</tr>\n";

}

}

if ($array[type] == "text" && $array[required] == "yes")

{

// this means nothing has been entered into the text field

if (!$text[$number])

{

$error[$number] = "<tr>\n <td colspan=\"3\">\n\t<font color=\"red\">You forgot to answer this Question</font>\n </td>\n</tr>\n";

}

}

// you can add as many of these as you want to, if more values have to be check for their validity

if ($array[type] == "text" && $array[required] == "yes" && $array[special] == "email")

{

// this will check if the entered value is a valid email address

if (!preg_match("/(\w+\-*)\@{1}(\w+\-?\w+)(\.\w+\-?\w+)*(\.{1}\w{2,3})$/", $text[$number]))

{

$error[$number] = "<tr>\n <td colspan=\"3\">\n\t<font color=\"red\">The email address you entered is not a valid one</font>\n </td>\n</tr>\n";

}

}





}

if (!$error)

{

// if the parser got to this point, it means everything required was filled in

// and the values were valid ones. so do whatever you want to do here and then exit the script

exit();

}

}

?>

<html>

<body>

<form action="<?php echo $PHP_SELF; ?>" method="post" name="submit_form">

<table border="0" cellpadding="0" cellspacing="1" bgcolor="#000000" width="80%">

<tr>

<td>

<table border="0" cellpadding="5" cellspacing="0" bgcolor="#CACACA" width="100%">

<?php

foreach ($options AS $number => $array)

{

// just delete $number if you don't want it to be displayed. But let the <td> intact

echo $error[$number];

echo "<tr>\n <td valign=\"top\" width=\"1%\">\n\t$number.\n </td>\n";

echo " <td align=\"left\" valign=\"top\">\n\t$array[question]\n </td>\n";



if ($array[type] == "radio")

{

echo " <td align=\"left\">\n\t";

$count = 1;

foreach ($array[options] AS $option)

{

if ($radio[$number] == $count)

{

$check = " checked";

}

else

{

$check = "";

}

echo "<input type=\"radio\" name=\"radio[$number]\" value=\"$count\"$check>$option $array[break]\n";

$count++;

}

echo " </td>\n";

}



elseif ($array[type] == "check")

{

echo " <td align=\"left\">\n\t";

$count = 1;

foreach ($array[options] AS $option)

{

if ($checkbox[$number][$count] == "on")

{

$check = " checked";

}

else

{

$check = " ";

}

echo "<input type=\"checkbox\" name=\"checkbox[$number][$count]\"$check>$option $array[break]\n";

$count++;



}

echo " </td>\n";

}

elseif ($array[type] == "text")

{

echo " <td align=\"left\">\n\t<input type=\"text\" name=\"text[$number]\" value=\"$text[$number]\" size=\"$array[size]\">\n </td>\n";

}

}

?>

</table>

</td>

</tr>

<tr>

<td>

<table border="0" cellpadding="5" cellspacing="0" bgcolor="#CACACA" width="100%">

<tr>

<td align="center" width="50%">

<input type="submit" value="Submit Form">

</td>

<td align="center" width="50%">

<input type="reset" value="Reset Form">

</td>

</tr>

</table>

</td>

</tr>

</table>

<input type="hidden" name="action" value="sent">
</form>



</body>

</html>

<<<<<<< end of index.php >>>>>>>

<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>

<<<<<< start of array.php >>>>>>

<?php

$options = array(

"1" => array(

"type" => "radio",

"question" => "hoe oud ben je?",

"options" => array("0-15","16-23","24-30","31-ouder"),

"break" => "<br>",

"required" => "yes"

),

"2" => array(

"type" => "check",

"question" => "waar programmeer je in?",

"options" => array("php","asp","geen van beide"),

"break" => "  ",

"required" => "yes"

),

"3" => array(

"type" => "text",

"question" => "wat is je email adres",

"size" => "30",

"required" => "yes",

"special" => "email"

)

);

?>

<<<<<<< end of array.php >>>>>>>
ziet er goed uit maar hoe kan ik de informatie als een bijvoegsel (.txt) bestand versturen als email?
wat wil je dan precies verzonden hebben, Nansjepansje(:S)

en wat is jouw vraag nouw pcies Patrick??
Nou Johan, ik wil gewoon dat alle gegevens die de mensen in gaan vullen, dat die naar m'n e-mailadres worden verstuurd. Maar hoe doe ik dat precies. Ik snap niet waar ik precies welk stukje script daarvoor moet plaatsen.

Bedankt voor de snelle reacties,

Nancy
Heb hem al veranderd :-D code staat hier helemaal boveaan

Nu nog 1 probleempje, hij checkt niet of alle vragen wel zijn ingevuld. Hij geeft als je de pagina opent al aan dat je alle vragen nog niet hebt ingevuld.
Dat klopt natuurlijk niet.
En hij verstuurt toch een mailtje, ondanks dat (hij zegt) dat je niets hebt ingevuld.

Greetings Nancy


<?php
include \"array.php\";

// everything between these {} will be done when the form is submitted

if ($action == \"sent\") {
$bericht = \"\";
$bericht = $bericht . \"Vraag 1,\". $text[\'Name\'] . \"<BR>\";
$bericht = $bericht . \"Vraag 2,\". $text[\'e-mailadress\'] . \"<BR>\";

$aantal = count($radio); //15 radio vragen
for($x=1;$x<=$aantal;$x++){
$bericht = $bericht . \"Vraag \" . ($x + 2) . \",\". $radio[$x] . \"<BR>\";
}

//echo $bericht;
$bericht = str_replace(\"<BR>\", \"\\n\", $bericht);
mail(\"[email protected]\", \"Answers Assessment Tools\", $bericht);
echo \"Your answers were send succesfully, thanks for your time!\";

}



// $options is the array that contains all the questions and their specifics. It\'s located in array.php

foreach ($options AS $number => $array)

{

if($array[type] == \"radio\" && $array[required] == \"yes\")

{

// this means none of the radiobuttons for this question have been checked

if(!$radio[$number])

{

$error[$number] = \"<tr>\\n<td colspan=\\\"3\\\">\\n\\t<font color=\\\"red\\\">You forgot to answer this question!</span>\\n </td>\\n</tr>\\n\";

}

}

if($array[type] == \"check\" && $array[required] == \"yes\")

{

// this means none of the checkboxes for this question have been checked

if (!$checkbox[$number])

{

$error[$number] = \"<tr>\\n<td colspan=\\\"3\\\">\\n\\t<font color=\\\"red\\\">You have to at least answer one of these options</span>\\n </td>\\n</tr>\\n\";

}

}

if ($array[type] == \"text\" && $array[required] == \"yes\")

{

// this means nothing has been entered into the text field

if (!$text[$number])

{

$error[$number] = \"<tr>\\n <td colspan=\\\"3\\\">\\n\\t<font color=\\\"red\\\">You forgot to answer this Question</span>\\n </td>\\n</tr>\\n\";

}

}

// you can add as many of these as you want to, if more values have to be check for their validity

if ($array[type] == \"text\" && $array[required] == \"yes\" && $array[special] == \"email\")

{

// this will check if the entered value is a valid email address

if (!preg_match(\"/^([a-z0-9_\\-]+\\.)*?[a-z0-9_\\-]+@([a-z0-9\\-_]{2,})\\.[a-z0-9\\-_]*(\\.[a-z0-9\\-_]{2,})*$/i\", $text[$number]))

{

$error[$number] = \"<tr>\\n <td colspan=\\\"3\\\">\\n\\t<font color=\\\"red\\\">The email address you entered is not a valid one</span>\\n </td>\\n</tr>\\n\";

}

}





}

if (!$error)

{

// if the parser got to this point, it means everything required was filled in

// and the values were valid ones. so do whatever you want to do here and then exit the script

exit();

}



?>

<html>

<body>

<form action=\"<?php echo $PHP_SELF; ?>\" method=\"post\" name=\"submit_form\">

<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#000000\" width=\"80%\">

<tr>

<td>

<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#CACACA\" width=\"100%\">

<?php

foreach ($options AS $number => $array)

{

// just delete $number if you don\'t want it to be displayed. But let the <td> intact

echo $error[$number];

echo \"<tr>\\n <td valign=\\\"top\\\" width=\\\"1%\\\">\\n\\t$number.\\n </td>\\n\";

echo \" <td align=\\\"left\\\" valign=\\\"top\\\">\\n\\t$array[question]\\n </td>\\n\";



if ($array[type] == \"radio\")

{

echo \" <td align=\\\"left\\\">\\n\\t\";

$count = 1;

foreach ($array[options] AS $option)

{

if ($radio[$number] == $count)

{

$check = \" checked\";

}

else

{

$check = \"\";

}

echo \"<input type=\\\"radio\\\" name=\\\"radio[$number]\\\" value=\\\"$count\\\"$check>$option $array[break]\\n\";

$count++;

}

echo \" </td>\\n\";

}



elseif ($array[type] == \"check\")

{

echo \" <td align=\\\"left\\\">\\n\\t\";

$count = 1;

foreach ($array[options] AS $option)

{

if ($checkbox[$number][$count] == \"on\")

{

$check = \" checked\";

}

else

{

$check = \" \";

}

echo \"<input type=\\\"checkbox\\\" name=\\\"checkbox[$number][$count]\\\"$check>$option $array[break]\\n\";

$count++;



}

echo \" </td>\\n\";

}

elseif ($array[type] == \"text\")

{

echo \" <td align=\\\"left\\\">\\n\\t<input type=\\\"text\\\" name=\\\"text[$number]\\\" value=\\\"$text[$number]\\\" size=\\\"$array[size]\\\">\\n </td>\\n\";

}

}

?>

</table>

</td>

</tr>

<tr>

<td>

<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" bgcolor=\"#CACACA\" width=\"100%\">

<tr>

<td align=\"center\" width=\"50%\">

<input type=\"submit\" value=\"Submit Form\">

</td>

<td align=\"center\" width=\"50%\">

<input type=\"reset\" value=\"Reset Form\">

</td>

</tr>

</table>

</td>

</tr>

</table>

<input type=\"hidden\" name=\"action\" value=\"sent\">

</form>

</body>

</html>
aan johan,
bedoeling is om de verstuurde gegevens van een formulier in een access database te importeren hier op een lokale pc, daarom dacht ik aan een bijvoegsel in een txt bestand......
wat wil je dan precies verzonden hebben, Nansjepansje(:S)

en wat is jouw vraag nouw pcies Patrick??


bedoeling is om een form te versturen als email met de ingevulde gegens als txt bestand zodat ik de gegevens lokaal kan importeren in een ms accesss database
Hoi Patrick,

dat is ook wat ik nodig heb. De gegevens worden nu heel makkelijk naar je e-mail verzonden.
Hieronder is ene voorbeeld van zo'n mailtje
Alle gegevens moeten hier namelijk ook in access terecht komen ;)


Name,kees
E-Mailadress,[email protected]
Vraag 3,1
Vraag 4,3
Vraag 5,4
Vraag 6,3
Vraag 7,3
Vraag 8,4
Vraag 9,3
Vraag 10,4
Vraag 11,1
Vraag 12,5
Vraag 13,2
Vraag 14,2
Vraag 15,1
Vraag 16,3
Vraag 17,2

Reageren