Results 1 to 5 of 5

Thread: Custom Form with custom php for data

  1. #1
    User
    Join Date
    04-27-10.
    Posts
    134

    Default 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:rintpost.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

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default 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
    Consulenza Contao CMS https://www.intco.it

  3. #3
    User
    Join Date
    04-27-10.
    Posts
    134

    Default 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!

  4. #4
    User
    Join Date
    06-19-09.
    Posts
    328

    Default 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
    Consulenza Contao CMS https://www.intco.it

  5. #5
    User
    Join Date
    04-27-10.
    Posts
    134

    Default 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:

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •