1

I am creating a form via module, that I wish to use for both insert and update. After the insert user has the option of going back to edit the values previously input. The issue that I encounter is with the update.

This function decides if insert or update

public function form()
{
    session_start();
    $tagdata     = $this->EE->TMPL->tagdata;

    if(isset($_SESSION['id'])){
        $variables   = array();
        $variables[] = $_SESSION['tags'];

        return self::buildForm('updateForm', $tagdata, $variables);

    }

    return self::buildForm('addDonation', $tagdata);
}

While this function handles the actual building of the form

public function buildForm($method, $tagdata, $variables = FALSE)
{
    $hidden_fields = array(
        'ACT' =>  $this->EE->functions->fetch_action_id('Meal', $method)
    );

    if($variables != FALSE){

        $conditionals = $this->EE->TMPL->simple_conditionals($tagdata, $variables);
        $conditionals = $this->EE->TMPL->parse_variables_row($conditionals, $variables);

        print_r($conditionals);

        $content = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);

    }

    //Build an array with the form data
    $form_data = array(
        "id"            => $this->EE->TMPL->form_id,
        "class"         => $this->EE->TMPL->form_class,
        'hidden_fields' => $hidden_fields
    );

    $form = $this->EE->functions->form_declaration($form_data) . $content . "</form>";

    return $form;
}

The output is currently {if FirstName != and {FirstName} within the conditional is not being parsed.

Any help greatly appreciated!

1 Answer 1

2

I think you're making this more complex than needed. This should suffice:

if($variables != FALSE)
{
    $content = $this->EE->TMPL->parse_globals(
        $this->EE->TMPL->parse_variables($tagdata, $variables)//preps then runs parse_variables_row()    
    );
}
5
  • Thanks for the help. Printed out $content from your example. It is returning the conditional {if FirstName != ....nothing. here is the markup from template value="{if FirstName !=""} {FirstName}{/if}
    – SuperNinja
    Commented Feb 13, 2014 at 0:51
  • Don't just print it out - use it in a template. The template parser still needs to run through it for the conditionals to be parsed. At this point they are only prepped, not actually parsed. Commented Feb 13, 2014 at 2:23
  • I must not be using correctly, sorry lil new at this... Here is where I am attempting to put the content back into my form, and it's not being parsed here. $form = $this->EE->functions->form_declaration($form_data) . $content . "</form>";
    – SuperNinja
    Commented Feb 13, 2014 at 2:59
  • That's correct - but just printing it out inside your add-on code won't yield what you expect. That final output still needs to be processed by the template parser, which happens when your front-end template which displays your form is loaded. Commented Feb 13, 2014 at 12:43
  • Thanks for the help. Guys over at Ellislabs straightened things out. Ended up being a simple variation on your suggestion. $this->EE->TMPL->parse_variables replaces $this->EE->TMPL->parse_variables_row , it does the prep work before calling $this->EE->TMPL->parse_variables_row -- If you would like to update your answer I'll be happy to accept.
    – SuperNinja
    Commented Feb 13, 2014 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.