$value. You can also, if you like, reference the entire incoming row via
$row. (This is fetched using
mysql_fetch_array, so both numeric and associative keys are set; e.g.
$row['employeeID']are both valid.)
displayValueattribute allows you to alter what shows up on the template. For example, let's say you've got a field in your employees table called "salary" which for some obscure reason is stored as an integer. You want to format it to a nice dollar amount. No problem! Here's what you do:
<sqlfield name="salary" displayValue="'$' . number_format($value / 100, 2)" />
SparsePage). Sparse will use
eval()to output the computed value.
<?php print $row['lastName'] . ', ' . $row['firstName']; ?>You can use
$rowanywhere inside the sqlrow tag.
returnValueto do that. Here's how it'd look:
<sqlfield name="salary" returnValue="(int)(substr($value, 1) * 100)" />
requiredindicates the value can't be blank;
numericensures the data must be a number;
maxrequire it to be greater or lesser than specific values. But you can indicate any constraints you like. The easiest way to do this is to create your own PHP function. The reason is because doing this will allow you to "personalize" your error messages (see Errors).
if (strlen($name) > 10) return 'Name is too long!';
mysql_query('SELECT name FROM employees WHERE name=' . $name);
if (mysql_num_rows) < 1) return 'Employee not found!';
<sqlfield name="name" constraints="employeeExists($value)" />
constraintstag evaluates to true, the value will be accepted. If it evaluates to false, a generic error message will be displayed. If it evaluates to anything else, though, it will print out that message. So it's a great way to define constraints without interleaving the code with the display!