Custom Form with custom php for data
Hi,
I've created a form with name, email etc and have a 'HTML Code' CP.
In the HTML CP I have an inserttag {{file::printpost.php}}
printpost.php:
Code:
<?php foreach ($_POST as $k => $v) {
echo "<input type='checkbox' name='" . $k . "' checked='yes' value='". $k ."'> " . $k . "<br/ >";
}
?>
When on the FE form page, the form shows properly with the post data within the form, but on submitting the form only the name and email address are being sent via email.
I have set the form to send as RAW.
Does anyone have any pointers as to why not all my form data is sent?
Thanks
James
Re: Custom Form with custom php for data
Because your "Html code" is not a field (for Contao, of course)
You have to change your approach to the problem
define a field of type "Checkbox menu" and change its values through the loadFormField hook
hope this helps
Re: Custom Form with custom php for data
Ok, I understand about Contao not seeing it as a proper field.
But regarding hooks and the like, I have no idea even where to start.
I've browsed that page many a times wondering if I'd ever need to use one of them having no idea how they worked!
Re: Custom Form with custom php for data
a starting point:
config.php
Code:
<?php
$GLOBALS['TL_HOOKS']['loadFormField'][] = array('MyHooks', 'myLoadFormField');
class MyHooks extends Controller {
public function MyLoadFormField(Widget $objWidget, $strForm, $arrForm) {
// formID is set in the Form Generator
if ($arrForm['formID'] != 'your_formID') {
return $objWidget;
}
$name = $objWidget->name;
switch ($name) {
case 'your_field_name':
// your code here
// see below for the link to the documentation
break;
}
return $objWidget;
}
the objWidget is an instance of Widget (or a class that extends Widget), documentation for CheckBox class:
http://api.contao.org/Controller/CheckBox.html
Re: Custom Form with custom php for data
Thanks ga.n - really appreciate that. Clears it up a bit for me to understand
Off on holiday for 2 weeks now so will check it all out when I return with a fresh head! :idea: