...

View Full Version : HTML Forms



Jockster
08-11-2010, 08:07 PM
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

Major Payne
08-12-2010, 07:43 AM
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.

Jockster
08-16-2010, 06:15 PM
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.

met
08-16-2010, 07:05 PM
well i'd go for the database approach but this would work also



<?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
/* 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">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>
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum