+ Reply to Thread
Results 1 to 4 of 4

Thread: Dynamic forms page

  1. #1
    Join Date
    Jan 2007
    Posts
    27

    Default Dynamic forms page

    My form page is generated dynamically from a database. It's a product order form and each product has a number of fields attached. I want to create a template which will suppress the display of the Product Details fields if the Quanity field is blank. However the field names are generated dynamically and I have no idea how many products there will be in the form.

    Is there any way of achieving this? Advanced Templates obviously needs to know the names of each field and so it won't handle it. Can I do anything with Computations as the form is submitted?

    I did wonder whether to write a php routine to dynamically create a template field every time the form is called, but that sounds like rather a major reworking of the form page, especially if there's a simpler way...

    Thanks for any help

    ===Toby===

  2. #2
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Dynamic forms page

    Hi,

    field names are generated dynamically
    That's interesting. Can I take a look at the form to understand why?

    One technique that works well, but is quite complicated, is to use the dynamic form itself (presumably in PHP) to generate its own template. I do this quite a bit for customers.

    So, the logic is a bit like this:

    PHP Code:
    <?php
    $sNextQty 
    GenerateFieldName();
    if (
    $_GET["template"])
    {
          
    //
          // this is the template generation.  it uses the advanced templates
          // <if> feature to skip the field if it wasn't entered
          //
    ?>
        <if $<?php echo $sNextQty?>>
           The quantity is $<?php echo $sNextQty?>
        </if>
    <?php
    }
    else
    {
          
    //
          // this is the form generation.
          //
    ?>
       Please enter your quantity: <input type="text" name="<?php
         
    echo $sNextQty?>" />
    <?php
    }
    ?>
    <!--
    Now tell FormMail to use this form for the template.
    -->
    <input type="hidden" name="mail_options" value="HTMLTemplate=thisform.php?template=1" ?>
    You need to set $TEMPLATEURL, not $TEMPLATEDIR, and set it to your basic URL.

    It saves you from having to create a template manually, but makes your form PHP a little more complicated.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

  3. #3
    Join Date
    Jan 2007
    Posts
    27

    Default Re: Dynamic forms page

    Quote Originally Posted by russellr
    Hi,
    That's interesting. Can I take a look at the form to understand why?
    Can I e-mail or PM you? The code is too lengthy to include here and in the middle of development so I don't want it released generally.

    The page lists the product details for every product and then as you enter the quantity you want to order various fields are updated using JavaScript (line total and Order Total in particular). But the product details are taken from a database so the client can update them. So the PHP does a couple of recursives to create table rows and fields are named according to the loop count - so you get PHP lines like (loop count is $i):

    PHP Code:
    echo "<input type=\"text\" name=\"Price$i\" value=\"£$currency\" size=\"6\" class=\"pricefield\" readonly> 
    - and of course you don't know how big $i is going to get or the contents of the fields.

    ===Toby===

  4. #4
    Join Date
    Dec 2003
    Posts
    3,901

    Default Re: Dynamic forms page

    Hi,

    Sure, we can continue via email: russmisc AT tectite DOT com.
    Russell Robinson - Author of Tectite FormMail and FormMailDecoder
    http://www.tectite.com/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. dynamic php generated html email not working
    By scrypton in forum FormMail Subscription Support
    Replies: 6
    Last Post: 04-Dec-2005, 12:11 AM
  2. Multipage forms, going back and subsequently losing data!
    By Martinjgriffiths in forum FormMail Subscription Support
    Replies: 1
    Last Post: 31-Jul-2005, 10:01 PM
  3. Multi-page Forms and $MULTIFORMDIR or $MULTIFORMURL
    By mga in forum FormMail Subscription Support
    Replies: 2
    Last Post: 30-May-2005, 12:06 PM
  4. Multi-forms and certain conditions
    By Chrisanna in forum FormMail Subscription Support
    Replies: 1
    Last Post: 22-May-2005, 09:32 PM
  5. Attaching Files from forms
    By Chek in forum FormMail Subscription Support
    Replies: 2
    Last Post: 14-Dec-2004, 11:32 PM

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