Multiple identical forms Dwoo

1

I have a form built using Template Engine Dwoo which has three variables (specific data for the attributes "name" and "value"), this form will be inserted multiple times inside another template but since the name of the variable must be the same as the key of the array of data that is passed in the invocation of the template, so how will I make the value of these variables to be modified with each new form?

Form template code:

<form class="form-inline" role="form" action="#" method="get">
    <div class="form-group">
        <label for="country">Country</label>
        <select class="form-control country" name="country">
            <option value="all">All (WorldWide)</option>
        </select>
    </div>
    <div class="form-group">
        <button class="btn btn-default" type="submit" name={$search} value={$search}>Search</button>
        <button class="btn btn-default" type="submit" name={$save_pdf} value={$save_pdf}>Save in PDF</button>
        <button class="btn btn-default" type="submit" name={$save_png} value={$save_png}>Save in PNG</button>
    </div>
</form>

PHP code that "printa" the template

<?php
    session_start();

    require_once '../../../vendor/autoload.php';

    $dwoo = new Dwoo\Core();
    $dwoo->setCompileDir('../../../assets/compiled/');
    $dwoo->setTemplateDir('../../../assets/templates/');

    $data = array();

    if((isset($_SESSION['email']) == true) && (isset($_SESSION['pass']) == true)){
        $data['page'] = 'site-statistics.php';
        $data['search'] = 'form_1_search';
        $data['$save_pdf'] = 'form_1_save_pdf';
        $data['$save_png'] = 'form_1_save_png';
        $dwoo->output('site-statistics.tpl', $data);
    }else{
        header('Location:index-admin.php');
    }
?>
    
asked by anonymous 12.07.2015 / 01:06

1 answer

1

To solve the problem of inserting multiple values into the same variable I change the location of the assignment of the variable of the file responsible for the view to the assignment prior to the form's inclusion in this way:

Form template inclusion code in the page template:

    {assign 'form_1_search' search}
    {assign 'form_1_save_pdf' save_pdf}
    {assign 'form_1_save_png' save_png}
    {include file='components/body/body-select-country2.tpl'}

PHP code that "printa" the template

<?php
    session_start();

    require_once '../../../vendor/autoload.php';

    $dwoo = new Dwoo\Core();
    $dwoo->setCompileDir('../../../assets/compiled/');
    $dwoo->setTemplateDir('../../../assets/templates/');

    $data = array();

    if((isset($_SESSION['email']) == true) && (isset($_SESSION['pass']) == true)){
        $data['page'] = 'site-statistics.php';
        $dwoo->output('site-statistics.tpl', $data);
    }else{
        header('Location:index-admin.php');
    }
?>
    
12.07.2015 / 01:06