Results 1 to 12 of 12

Thread: Can I show/hide a Form Generator form based on a condition?

  1. #1
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Can I show/hide a Form Generator form based on a condition?

    I'm wondering if this is possible...
    I wish to show a form made in Form Generator ONLY if a members credits are >0.
    The forms FormID is "FormJoblisting2".
    In a php script can I somehow pull in this form?
    eg:
    Code:
    if(condition is met){
    What code would present FormJoblisting2
    }

  2. #2
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Can I show/hide a Form Generator form based on a condition?

    You can place the FORM on a hidden Page in an article/CE ready. Then you do your condition in a CE/Template and then use the {{insert_article::ID}} inserttag to "call" the form display. This way you only need to write the conditional code part.

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Hi Thyon, thanks but I can't get this to work.
    I am trying to do it from a php file in the Templates folder.
    In my php script
    Code:
    echo "{{insert_article::544}}";
    just echos that string, and if i try to do it with echo and no " " then Typolight throws a wobbly
    Parse error: syntax error, unexpected '{'
    and not using echo at all gives
    Parse error: syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '$'
    .

  4. #4
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Can I show/hide a Form Generator form based on a condition?

    No, look at other TL samples:

    Code:
    <?php if ($myvar > 0): ?>
    {{insert_article::544}}
    <?php endif; ?>
    DO NOT echo the inserttag, that is your mistake. To call your php file, you need to use and inserrtag to call it. Why not simply write a small CE/Module to display the front-end, because you're not trying to use an inserttag inside of an inserttag (which is also another problem).

  5. #5
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Why not simply write a small CE/Module
    I think I'll need too, I'm running into problems every way I turn at the moment.
    Besides, it'll be good practice.

    Something I discovered just now (and i bet you didn't know this!): I can pull the form into the php with this line
    Code:
    echo $this->getContentElement(544);
    YAAAYYYY! but....

    the inserttags used in the form now just show as strings! BOOOOOO!
    I see what u mean re: insert tags within insert tags....
    so I think little module it is....

  6. #6
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Yes I knew that, because that exact function/method is called when the inserttags are replaced

    The module should be pretty straight forward to create. You might want to add some config parameters in your BE module:
    Back-end: tl_module.php (extended) -- look at all the news, etc. to see how they add their own DB, module parts.
    1) Have a place where to choose what parameters, e.g. member cost > 0, etc.
    2) Select the Form you'd like to render (look at the catalog module to see how I retrieve the form list)

    FrontEnd: ModuleConditionalForm.php
    1) query the DB to retrieve the total credits,
    2) set the template variables and in your template you can do the magic.

    Just remember to write your own extensions like this (member_costing), so that your module is activated AFTER the member module (as TL loads extensions alphabetically). Then you can publish this, together with your membership credit module

  7. #7
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Yes I knew that,
    ... i should have known better! :D

    The backend module is mostly done.
    I just got stuck on tying the Form Generator form into the front end, and decided to use a standalone php script to do this ( i mostly do this, as i find it easier, but in this case its a battle).
    Thanks for the heads up, i'll have a go using FE Mod/FE template concept instead and see.

  8. #8
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    All going well....but a question.
    Code:
    //WHEN THEY SUBMIT THE JOBSLISTING FORM
    //test to see if form posted
    if ($this->Input->post('FORM_SUBMIT') == 'FormJoblisting2')
    	{
        $test = "THE JOB FORM FIRED";
    //need to unset $this->Input->post('FORM_SUBMIT') below
    
    	}
    How can I unset (or even change) the value of
    Code:
    $this->Input->post('FORM_SUBMIT') == 'FormJoblisting2';
    Unset() won't work, nor will
    Code:
    $this->Input->post('FORM_SUBMIT') = 'NothingOrSomethingElse';

  9. #9
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Can I show/hide a Form Generator form based on a condition?

    its because the ->post() function retrieves it from $_POST[], where you need to "unset" it. why do you need to unset it anyway, you can just use the existing form HOOK, to send it to your function to process the form??

  10. #10
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    I'd rather unset it if I can.
    (i've never used hooks,i will learn but later)
    Is it possible/how would I unset it with $_POST[]?

    (btw you're into flash yeah? check this if you've not come across it, i think its fantastic!)
    but answer my question first! :P

    http://megazine.mightypirates.de/

  11. #11
    Experienced user
    Join Date
    06-10-09.
    Location
    Cape Town, South Africa
    Posts
    1,387

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Hey ramjet.

    Sorry I didn't get this reply.

    Leo cleverly sets a $SESSION['FORM_DATA'] variable for posting, so I don't think your unset() will work. You can just try:
    Code:
    unset($_POST['myformvar']);
    ... that should do it.

    Normally the process for forms is like this:
    => FORM display (in module or CE)
    => FORM POST (same page) => TL processes the form (stores/emails) => passes control to the HOOK processFormData
    => redirected to "Thanks" page.

    You can use the HOOK to perform form processing things and you can use the formID to ensure that only the right form is processed.

  12. #12
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Can I show/hide a Form Generator form based on a condition?

    Thanks Thyon.
    Its funny, it seems that in trying to build a module.... the more you do, the more there is to do!
    :?

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
  •