Inserting Your Own Code into the RazorForm Output
As mentioned above, $rf->get_form() spits out the entire
form. Internally, this method just calls a few other RazorForm object
methods which you can call yourself instead of calling
$rf->get_form(). You would want to do something like this
in the case that you wanted to insert some of your own code at some
point in the RazorForm output.
$rf->get_form() calls the following in order:
- $rf->start_form()
- $rf->get_rows()
- $rf->end_form()
$rf->start_form() prints out the beginning code of the
form. It accepts a single optional argument of true or
false (default true) telling it whether or not to
include the <form> tag. So you could do something like
this (assuming you had already created a RazorForm object called
$rf):
<form action="foo.php" method="post">
... insert your own stuff here ...
<? $rf->start_form(false); ?>
The output of $rf->start_form() will have anything
necessary to get the form started. This will include the opening
<table> or <div> tag (depending on the layout) and any
stylesheet definitions the layout needs to set to organize the row as
it sees fit. It will also include any hidden input fields that were in
the form definition before any rows were defined.
$rf->get_rows() prints out the rows of the form. It
keeps track internally of what rows have been printed already, and it
will start printing from the next row after that. get_rows() accepts
two optional arguments which must be integers. If you give it neither
of these, it will print out all rows of the form from the current row
to the last. So if nothing has been printed yet, the current row will
be at 1, and the whole form will be printed. If you pass get_rows()
only one integer, it will print out that many rows, starting at the
current row. Finally, if you give it both arguments, it will see these
as startrow and endrow, and print out all rows
starting with startrow and ending with endrow, inclusively. This last
scenario ignores the whole question of what the current row was to
start out with, but it does reset the current row to be the one
immediatedly following endrow. If endrow is greater than the number of
rows in the form, get_form() will print from startrow up to the last
row.
$rf->get_row() prints out one row at a time. If you give
it the optional integer argument, it prints out the row with that row
number. If you call it without the argument, it prints out the next row
after the last one printed, according to the internal pointer mentioned
in the previous paragraph.
You can reset the internal current row pointer back to 1 by calling
the $rf->resest_curr_row() method, which takes no
arguments.
NOTE: The row numbering for the $rf->get_rows() and
$rf->get_row() methods is NOT zero-based indexing. It
starts at 1 and goes up.
Using $rf->get_rows() and $rf->get_row(),
you could do something like this (note that in this case we don't type
out a <form> tag because we don't pass a false
to $rf->start_form()):
<? $rf->start_form(); ?>
<? $rf->get_row(); ?>
... put your own stuff here ...
<? $rf->get_row(2); ?>
... more of your own stuff ...
<? $rf->get_rows(3,7); ?>
... more of your own stuff ...
<? $rf->get_rows(); ?>
<? $rf->end_form(); ?>
Usually you wouldn't use both methods of access like shown here. In
a single form, you'd likely only access rows by current row pointer or
by explicit row numbers. In other words, you'd use only get_row() with
no arguments and get_rows() with zero or one arguments, or get_row()
with one argument and get_rows() with two arguments.
When doing something like the above example, keep in mind that the
places where you insert your own stuff will be inside of the overall
form table at this point. This could be either a traditional HTML table
or an arrangement of divs and spans, depending on which layout you're
using. The default layout uses an HTML table, so in that case you'd
want to put whatever of your own stuff you were adding into its own
<tr> and <td>.
$rf->end_form() is the counterpart to
$rf->start_form(), printing out the </table> or the
final </div> (depending on the layout). Like
$rf->start_form(), it takes an optional argument
$formtag, which is a true or false telling
it to print out the final </form> tag or not, default
true.