473,807 Members | 2,853 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 1521

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

Similar topics

2
2132
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
1999
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
2297
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
3944
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
3943
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
1619
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
5669
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
1770
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
9720
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
9599
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
10372
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...
0
10112
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
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3854
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.