sqlfield
Tag
sqlfield
will turn into
text (for display
templates) or an input
element (textbox, textarea, select box etc.) for the other template
types.name
must be
unique in all cases, except if the type
is radioSingle
or checkSingle
. If you used aliases
in your query, you'll have to use the alias name here.
text
: Plain
text (i.e. not editable at all). textfield
: A
plain ol' text field. Available to all SQL types. Default type
for char, varchar, integer, and real types.textarea
: A
large text area. Available to all SQL types. Default type for
tinytext, text, and longtext types.password
: A
text field with password hiding. For all SQL types.radio
: A set
of radio buttons. Only available to "enum" or "set" fields, or if
the enum
attribute is set on this tag.radioSingle
:
A single radio button. The value
of the button can be set with the value
attribute. If you use an enumset, you can automatically display the
label. Otherwise just write the text next to the button.checkbox
: A
set of checkboxes. Only available to "set" fields, or if the enum
attribute is set on this
tag.checkSingle
: A single checkbox; works
identically to radioSingle
.select
: A
drop-down listbox. Only available to "enum" or "set" fields, or if
the enum
attribute is set on this tag. Default type for enum.selectMultiple
:
A list which allows multiple selection. Only available to "set" fields,
or if the enum
attribute is set on this tag. Default type for set.hidden
: A
field which doesn't show up. You can use this to automatically fill in
fields for an add
template, or to give two fields the same value in edit templates, e.g. for foreign
keys.MySQL Type | Sparse Type | Sparse CalType |
---|---|---|
TEXT LONGTEXT |
textarea | |
DATE | calendar | y/m/d |
DATETIME | calendar | y/m/d h:i:s |
TIME | calendar | h:i:s |
TIMESTAMP | calendar | y/m/d h:i:s |
SET | selectMultiple | |
ENUM | select | |
Everything else |
textfield |
date()
function in
that it allows you to
print out fields for day, month, year, hour, minute, and second
depending on what you put in your calType.
The following letters are recognized as of now (case-insensitive):y | Year |
m | Month |
d | Day |
h | Hour |
i | Minute |
s | Second |
date()
syntax. See the PHP
reference for more information. Note that PHP date() is case-sensitive,
so the use may be slightly different than Sparse's current syntax (for
example, the full year is a capital Y, and full hour is a capital H).true | false
value
attribute. This will set the text value (in
textareas/textfields/passwords) or the selected item (in all the
rest). Note that this only takes regular text; if you need to use a
more complex expression, use the displayValue
attribute instead. You can
also use this attribute to set the value
attribute of the tag for a radioSingle
or checkSingle
field;
again, if you need a more complex expression, use returnValue
.true
for the value to be
accepted. If it evaluates to false
, a general
error will be printed; if it evaluates to anything else, that will be
taken as the error. You can use $value
to
refer to the entered value, or $row
to refer
to the entire entered row.<sqlfield name="amount"
constraints="is_numeric($value) && $value >= 5"
/>
<?php
include('Sparse.php');
function is_valid_customer_id($val)
{
//search your database and check if an ID is valid.
//return true, "Invalid ID!", or "Valid ID but not
a customer!"
}
SparseThisPage($username, $password);
?>
<!-- first part of template goes here-->
<sqlfield name="id"
constraints="is_valid_customer_id($value)" />
<!-- rest of template goes here -->
true | false
If set, the value entered by the user must be numeric.
This is the same as setting constraints
to is_numeric($value)
.
constraints
to $value <= max
.$value >=min
.constraints
to trim($value) != ''
constraints
, you can use $value
to
indicate the SQL data value and $row
to
indicate the rest of the row. For example, you can format an integer
number of cents to look like a dollar amount:<sqlfield name="amount" displayValue="'$' .
number_format($value / 100, 2)" />
constraints
,
you can use $value
to refer to the incoming value and $row
to
refer to the incoming row.. For example, you can remove all dashes
and spaces from the value before putting it in a date or integer field:<sqlfield name="startDate"
returnValue="str_replace(' ', '', str_replace('-', '', $value))"
/>
enum
keys with their values when displaying the
field, while keeping the
original value as the one sent to the server. In particular:<sqlfield type="textfield" size="15"
class="myTextFieldClass" />
<sqlfield type="textarea" cols="10" rows="10" />
The style
and class
attributes for a text
widget, if given, will be put into a <span> tag enclosing
the value.