473,695 Members | 2,302 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reusable form functions

Like me, you are probably confronted with many requests for surveys,
questionnaires, feedback forms, registration forms and so forth: forms
where the processing requirements are very simple (store in a database or
e-mail to a particular address).

Despite the simple requirements, there is often quite a lot of work
involved: crafting a database to store results, writing a function to
store the data to the database, one to verify submitted data (e.g. make
sure that if you've asked for an e-mail address, it contains an @-sign),
and marking up the form itself (which can be quite a task if you want to
make correct use of <label>, <th scope="blah">, etc.

So I introduce my reusable form functions, with the rather unglamorous
name of inc_surveytool. php v1.0.

http://tobyinkster.co.uk/Software/inc_surveytool.phps
http://tobyinkster.co.uk/Software/inc_surveytool.txt

They are far from finished (expect a 1.1 and a 2.0 version soon -- I have
big plans for them). Despite being 1.0, I think there is still a lot of
work to be done, and I'd like some feedback.

If you needed to sum them up in one pithy line: It's an entire programming
language for creating and validating HTML forms.

Here is an example of what you can do with them:

<?php
include 'inc_surveytool .php';

print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n";
print " \"http://www.w3.org/TR/html4/strict.dtd\">\n ";
print "<title>Exa mple Form</title>\n";

$widgets = "Form
ma*******@examp le.com
multiplesubmiss ions=1
showsubmissions =0

Text 1 100 / /
name=Please enter your name:

Integer 1 150
age=Please enter your age:

Multi 1 3
statements=Whic h of these statements do you agree with?
1=Foo is good.
2=Bar is good.
3=Quux is good.
4=Flibble is good.
5=Blah is good.

GridSingle
satisfaction=Pl ease rate the following.
Cols
1=Excellent
2=Good
3=Average
4=Poor
5=Rubbish
Rows
foo=Foo
bar=Bar
qux=Quux
flb=Flibble
blh=Blah

Units Volume 5
vol=How much do you like Foo?";

form_Main($widg ets);
?>

This will display a semantically– marked-up (even nicely indented!) form
containing:

* an input for the user's name, which will be checked to be between 1
and 100 digits, and checked that it matches the perl-compatible
regular expression / / (i.e. it must contain a space character);

* an input for the user's age, which will be checked to be an integer
between 1 and 150 upon submission;

* five checkboxes asking them what they agree with: they must tick
between 1 and 3 boxes;

* a table allowing the user to rate some things on a scale of 1 to 5;

* an input allowing the user to enter a physical volume in a choice of
kilolitre, litre, millilitre, brpint, fluidounce, m^2, cm^2, mm^2
with m^2 being the default.

When the form is submitted, it will be validated and e-mailed to
me@example.com. The submission will be stored in a database. You would be
able to visit the form, adding a query string "?adminscreen=1 " to view the
results. (Security is handled by editing a function called form_WhoisAdmin
which can test for IP address, cookies, session data, etc.)

(Oh, and the physical volume I mentioned is converted to litres and stored
in both the user's chosen units, and the converted units for easier
sorting!)

If the users are logged in, or may be uniquely identified somehow (exactly
how to identify each user is specified in function form_Whois, which can
be customised for your own site) then it is possible to allow or disallow
multiple submissions for one user, and to control what happens when there
are multiple submissions (the new submission could over-write the old one,
or the submissions could be stored alongside each other). Users returning
to the form are able to view previous submissions.

Anyway, all this is only the tip of the iceberg -- it's a very flexible,
very capable library of form-building functions.

The reason I post is that I'd like some other people to try it out and get
a feel for how it works and what more is needed. I'd also like people to
point out any obvious security flaws.

Requirements:

* PHP 4.3;

* an SQL database (PostgreSQL supported, MySQL has been catered
for, but not properly tested);

* GNU Units ("/usr/bin/units") if you want to be able to use the
Units widget.

There is almost zero documentation, so if you'd like to use it, do drop me
an e-mail (mail at tobyinkster.co. uk) and I'll try to answer any
questions. If there is demand, I might even set up a mailing list.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Nov 22 '05 #1
0 1516

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2123
by: John | last post by:
Hi, I have a data driven application which has some generalized components. So, for reuse, I am building the components so they can be reused in other projects ... it takes almost no extra effort, just a bit of planning. Following the security convention of only giving the user as much access as required, I always create at least 2 users for each app; owner & user. And recently I've had a cool idea for handling multiple sites with...
3
1994
by: Axter | last post by:
I'm wondering about the practical use of dynamic_cast in reusable or generic code. I'm currently working on a smart pointer that can be used on vector and other STL containers. See following link: http://code.axter.com/arr_ptr.h In above code, there's a function called clone_func_ptr_interface within the func_ptr_holder class. In this function, I need to cast from a base pointer to a derived
27
2276
by: Matt Kruse | last post by:
Since this topic has come up several times in other threads, I thought I'd make a separate thread and gather opinions from (hopefully) a more varied range of newsgroup participants. What are your thoughts on the development and use of generalized, reusable javascript libraries? Discussion points: 1) Is the overhead of a 25k (for example) .js file too much for a typical
2
3940
by: DaleMan | last post by:
Where can I learn more about reusable businesss objects and their uses? I've been reading that one of .Net's advantages is that a developer can write reusable business objects. I would like to implement these into my code and make it more portable. Thanks, Dale
3
3927
by: Nikki | last post by:
Hi, I would like to create a central storage place for javascript functions that I can then access from any of my asp.net projects. An example of what I need it for is as follows: I have a class library that contains a function I use all the time (to create a link around some text). That function in turn calls a javascript function. Usually I would have put the javascript on the
3
1613
by: Danny | last post by:
In classic ASP, if I have a function that will be used many times, I just put it in include file, and add, for example <!-- #include file='myfunction.inc' --> in the file where I want to use that function. How do I do this in ASP.Net? Got bit confused, especially because HTML and the VB.Net code is located in separate files. Thanks in advance, - Danny
10
5656
by: Josselin | last post by:
(Mac 10.4.6 , Firefox/1.5.0.3 Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.8.0.3) Gecko/20060426 ) I am trying to setup a Reusable Image Cache in JS ( as per http://www.devx.com/webdev/Article/20947 ) In order to o survey the events from image loading in a group container, It seems necessary to perform the following function, ImagePair(file) . Unfortunatly Firefox javascript checking mentions an error with this
1
1765
by: Nacho | last post by:
Hello.. I have one problem with my reusable function to validate date.. I want to use this function to all my web project no validate date, but It's works fine if I have one textbox to validate in the same form, If I have two textbox the return doesn't works correctly.. how can I do this? if (document.Form1.TxtFechaIng.value!=''){
0
8635
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8574
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9119
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8994
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.