Sparse - Frequently Asked
What is Sparse?
A. Sparse is
an open source,
framework which allows web
developers to make entire CGI applications without ever programming
anything - and tossing full Ajax functionality in, to boot. All that's
required is knowing how to use a few extra HTML
tags and sticking a single PHP
tag at the top. For a quick intro, click
What can Sparse do?
can deal completely
with adding, editing, and displaying data;
navigating amongst data; sorting and searching; checking and displaying
errors. Sparse will
also cache itself so that it only has to get information about the
tables and template once.
Why is Sparse
allows developers to
simply write plain HTML pages with
representing widgets and buttons for displaying or entering data,
similar to XUL.
Changing the look or behavior of your form is as simple as changing a
tag attribute or moving the tags around. Programming code isn't
required at all, though it can be easily augmented with code.
What does Sparse mean?
A. Well, I
guess you could say it stands for "SQL
with some acrobatics
making the P stand for PHP (it's not like they
didn't do it). With the new Ajax functionality, maybe I could argue the
A is Ajax. And maybe "sparse", as in "not dense", means you've got
a framework that doesn't have too many elements and is easy to
understand and use. But really, I just wanted a real English word of
one or two syllables that made sense.
Why was Sparse designed?
A. The need
for Sparse arose
from my own experiences in coding PHP backends, when I found myself
doing much of the same things over and over again, and my introduction
to Microsoft Access "forms", which allow you to define a user interface
that's "attached" to the data. The template for it
came from my work in writing Firefox extensions, and my exposure to XUL, which
impressed me by its combination of usability and flexibility.
Who's behind Sparse?
A. As of
this writing (October 2006), Sparse was coded and documented entirely
myself, Daniel Orner.
I am currently an M.Sc. student at York University. My thesis is based
a Firefox extension. I am also the creator and webmaster of
What requirements does Sparse have?
A. Sparse is
programmed in pure
PHP, with no external dependencies. It has been tested with PHP
v4.3.8 and MySQL v.3.23.58. It should work
with later versions of PHP and MySQL as well. It will not work well
with PHP versions less than 4.3, but the MySQL version shouldn't matter
Do I have to know PHP to use Sparse?
A. No, you
don't! You can use
PHP to make your applications do a whole lot more, but you can easily
use Sparse without ever writing any PHP. All you need to know is SQL
and HTML. (CSS can also make your life easier, but it's not
How is Sparse different from template engines like Smarty?
engines are designed to separate application logic from business logic.
Though that's an excellent and laudable goal, it's not what we do.
Sparse is firstly much more specific; it deals only with the common
task of SQL programs. Sparse tries to do
as much of the
application logic as it can, meaning you don't have to program it at
all. Other than a few bits and pieces here and there (such as user
validation, error displaying, etc.), all of which can be done without any full
PHP code at all, presentation is pretty much all there is.
Are there any disadvantages to using Sparse?
A. The beta
version does have
some issues (including, we expect, many which we haven't even detected
yet), which is why we don't recommend it being used for critical
applications. For one thing, the
Sparse tag reference may change drastically while we figure out exactly
what we need to do, so if you use it now you may find that a later
version of Sparse might not read your template properly. However, we
anticipate that the release version of Sparse will be safe, robust, and
fairly stable, so anyone who can help test the beta would get us that
much closer to our goal!
What can I do to
A. Sparse is
currently in beta,
testers! Although it
extensively tested and seems to be fairly stable, it hasn't been
destruct-tested, nor has it been tested on different platforms or
versions of PHP/MySQL. We are also extremely interested in suggestions
for changes to the tag definitions and reference, so please weigh in on
We also need a bit of help with our website, which looks a bit, well,
sparse. Let us know if you can snazz it up a bit!
How do I install Sparse?
A. You don't
have to install it at all. Just put the PHP files in any directory and
include them in your HTML file. For example, you can put them in the
/www/sparse/ , and then at the top
of every file you use
Sparse with, you just put the following:
Don't forget that your server will have to parse your HTML file using
PHP, so generally you'll have to save it with the file extension .phtml
What do the colors in the documentation mean?
words mean an HTML tag.
Blue words mean an HTML attribute.
Pink words mean a value
of an HTML attribute (e.g. display
Does Sparse require that the user have cookies enabled?
uses PHP's session
behavior by including the following directive before you call
still work fine.
Sparse is acting weird or messing up! What's wrong?
can get confused a couple of ways. Firstly, you can check the warning
log for some indications of things you may be doing wrong (see Configuring Sparse). Here's
a checklist of
shouldn't be doing:
Many important errors other than the ones mentioned will be
in the warning log.
- Don't try to include two
fields with the exact same name.
Alias them if you must (i.e. have one of them with a name like
- Don't have the
inside a regular
HTML tag's attribute; Sparse will think it's a comment. (You can
in an attribute of one of Sparse's special tags though.)
have the string
inside a string or comment in a PHP tag (i.e. anywhere but at the end).
Sparse will think it's
at the end of the PHP tag.
- Be careful when
rows from a template which uses
multiple tables. Make use of the deleteTables
- Some sqlaction
buttons will be ignored depending on the type of the template; see sqlaction
for more details.
- Be careful when putting tags
such as <body> or <head>
in comments. Sparse may get confused when inserting Ajax stuff.
- If you're using add or "mass edit" templates, don't put any
Sparse tags between the end of the sqlrow
the sqlaction button.
Can I interleave Sparse forms with my own?
Yes. You can use regular <INPUT> tags inside an
sqltemplate tag and it'll
normally; you can deal with it inside your PHP code. Just ignore
beginning with "
or "SPARSE" in $_REQUEST. You can use this to e.g. upload files, get
have nothing to do with the defined tables, etc.
Can I put other PHP tags in my Sparse template?
A. Yes, you
can include any PHP code you want! Take a look at the Advanced PHP Usage page
Can I embed a Sparse tag inside another tag or attribute?
Yes! You can use this to e.g. print out part of a link. For example:
Note that although this is not
valid HTML, by the time Sparse is finished with it, it will be. 8-) The
entire sqlfield tag will
be replaced by a single value.
Q. Can I nest Sparse
templates (i.e. place one within another)?A. Unfortunately, allowing
nested templates would be very difficult in the current implementation
and would require making the Sparse code significantly more complex
than it is now. There are no plans to implement this at the moment.
I have a field which is a foreign key. Can I "link" it so that only one
widget is used in my template?
A. You can
use a hidden
tag to do this. Let's say you have two fields "myField1" and
"myField2". Create your sqlfield
widget with the name myField1, then create another
with the name myField2,
whose type is hidden,
and set its displayValue
When the row is
updated, both fields will be given the same value.