Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: HTML Forms

  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HTML Forms

    I have several forms that use the select option. The list of the selections are continually updated by me. I was wondering if there is a way for me to create a seperate file with all of these options and include them into my forms so that I don't have to update each and every form. These forms are used to submit information to internal staff.
    I have used includes before but only for the "Look and feel" of the website.

    Thank you in advance,
    Jockster

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    MS
    Posts
    836
    Thanks
    10
    Thanked 79 Times in 77 Posts
    Includes would only work when you want to update same content that appears on many pages of your site. Look and feel is not its intended purpose. Using one include file would work if ALL your forms are on one page, then you could edit it, but that's the same as editing all the forms anyway.

    Maybe a Content management System (CMS) might work for you.
    ☠ ☠RON☠ ☠

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank you

    Thanks for your reply Major Payne. I have many forms with one common input select list and that gets submitted into a php mysql back end. I tried using the includes to get the list and that worked visually, but the submission into mysql reflected only a blank field in the record. Just wondered if this was a php issue or an html issue. The form works perfect without the includes feature. Thank you in advance.

  • #4
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    well i'd go for the database approach but this would work also

    PHP Code:
    <?php
    /* pinched the html code from CF */
    function makeSelectBox()
    {
       
    $box'<select style="width: 175px;" onchange="this.form.submit()" name="vote">
                <optgroup label="Choose a rating">
                    <option value="5">5 : Excellent</option>
                    <option value="4">4 : Good</option>
                    <option value="3">3 : Average</option>
                    <option value="2">2 : Bad</option>
                    <option value="1">1 : Terrible</option>
                </optgroup>
            </select>'
    ;

       return 
    $box;

    }
    ?>

    /* save that in your includes or wherever
     then simply */

    <!-- this is my form -->
    <input bla bla -->

    <?php echo makeSelectBox(); ?>

    <submit bla bla>
    like that ?

    PHP Code:
    <?php
    /* or better yet, pass the function a $name value,
     so you can refer to it as you need in your php scripts with post/get etc
    */

    /* pinched the html code from CF */
    function makeSelectBox($name='default_value')
    {
       
    $box'<select style="width: 175px;" onchange="this.form.submit()" name="' $name '">
                <optgroup label="Choose a rating">
                    <option value="5">5 : Excellent</option>
                    <option value="4">4 : Good</option>
                    <option value="3">3 : Average</option>
                    <option value="2">2 : Bad</option>
                    <option value="1">1 : Terrible</option>
                </optgroup>
            </select>'
    ;

       return 
    $box;

    }

    echo 
    makeSelectBox('rating');
    // returns

    <select style="width: 175px;" onchange="this.form.submit()" name="rating">
                <
    optgroup label="Choose a rating">
                    <
    option value="5">Excellent</option>
                    <
    option value="4">Good</option>
                    <
    option value="3">Average</option>
                    <
    option value="2">Bad</option>
                    <
    option value="1">Terrible</option>
                </
    optgroup>
            </
    select>
    ?>
    Last edited by met; 08-16-2010 at 07:08 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •