Proposal for "HTML_FormPersister"

» Metadata » Status
» Description
Modify HTML-form adding "value=..." fields to <input> tags according
to $_REQUEST, "selected" attribute to <select> etc. A lot of other
functions (e.g., select, textarea, img also supported).

The simplest example:


<?php
include_once "HTML/FormPersister.php";
ob_start("ob_formpersisterhandler")
?>
<form>
<input type="text" name="simple" default="Enter your name">
<input type="text" name="first[a]" default="Enter your name">
<input type="text" name="second[a]" default="Enter your name">
<input type="submit">
</form>


Clicking the submit button, you see that values of text fields
remain unchanged - the same as you entered before submitting the form!
The same method also works with SELECTs, CHECKBOXes etc. You do not need
to manual write "value=..." or "if (...) echo "selected" in your scripts,
it is done automatically based on $_GET and $_POST arrays.

Interesting feature (but OPTIONAL - please say if you thing it is NOT NEEDED, I will remove) - handling of "flip-fields". For example,

<select name="sel" multiple flip>
<option value="first" selected>First</option>
<option value="second">Second</option>
<option value="third" selected>Third</option>
</select>

(watch "flip" attribute!) gives the result:
$_REQUEST['sel'] === array('first'=>1, 'third'=>1)

It is much more logical to work with associative array instead
of lists for multiple SELECTs. See example:
http://pear.dklab.ru/test/FormPersister/t_formpersister.php /> (I say again: this is NOT required and NOT major (but - useful) option of the module, vote against it if you think it should be removed).
» Dependencies » Links
  • HTML_SemiParser
» Timeline » Changelog
  • First Draft: 2005-01-17
  • Proposal: 2005-01-17
  • Call for Votes: 2005-02-01
  • Voting Extended: 2005-02-09