Prev | Current Page 427 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


Processing Form Values
Once the form is submitted, you??™ll want an easy means to retrieve the form values.
Three methods are available: getSubmitValues(), process(), and exportvalue().
The getSubmitValues() method returns the submitted values by way of an array, as in
this example:
if ($form->validate()) {
print_r($form->getSubmitValues());
}
This produces output similar to the following:
Array ( [username] => jason [email] => wj@example.com )
The process() method passes values to a function. For instance, suppose you
create a function for communicating with Amazon??™s Web services named
retrieveBook(). The user data could be passed to it like so:
if ($form->validate()) {
$form->process('retrieveBook');
}
Finally, the exportvalue() function will selectively retrieve each value by specifying
its field name. For instance, suppose you want to retrieve the username value
defined by a username form field:
if ($form->validate()) {
$username = $form->exportvalue('username');
}
CHAPTER 13 ?–  FORMS 363
Using Auto-Completion
HTML_QuickForm comes with an amazing array of features, and the surface has hardly
been scratched in this chapter. Beyond the forms creation, validation, and processing
features, HTML_QuickForm offers a number of advanced capabilities intended to further
enhance your Web site??™s forms features. One such feature is auto-completion.
Sometimes it??™s useful to provide the user with free-form text input rather than a
drop-down box containing predefined values, in case the user??™s answer is not one of
the available choices.


Pages:
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439