Multiple identical Dwoo forms

Asked

Viewed 49 times

1

I have a form built using the Template Engine Dwoo which has three variables (of data specific to the attributes "name" and "value"), this form will be inserted multiple times within another template but as the variable name has to be the same as the data array key that is passed in the template invocation, so how will I change the value of these variables to 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>

Code php 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');
    }
?>

1 answer

1


To solve the problem of inserting multiple values into the same variable I change the value assignment location of the variable of the file responsible for the view to the previous assignment to the form include in this way:

Form template inclusion code in 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" to 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');
    }
?>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.