Re: Resetting drop-downlists in input-fields for texts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 21 Jan 2008 17:23:34 +0100, "Daniel Brown" <parasane@xxxxxxxxx> wrote:

    The only way I can think of that would allow you to do it is to
dynamically-name the fields in the form.  By doing so, AutoComplete
won't be able to recognize the fields, and you should be in good
shape.  In the example I'm sending, keep in mind that input should
still be sanitized properly, and it's by no means as a
copy-and-paste-for-production script.

<?

session_start();

if($_POST && isset($_SESSION['target'])) {
        /*This is just here for demonstration.
        Do your processing as you'd like with the
        POST data here.  There are two methods
        shown.  Note the use of the curly brackets
        and square brackets, as well as the order
        in which they're typed.*/

        /* Method 1: for()
        for($i=0;$i<count(${$_SESSION['target']});$i++) {
                echo ${$_SESSION['target']}[$i]."<br />\n";
        }
        */

        /*Method 2: foreach()
        Further handling would be needed to make the
        variables valid, because $0, $1, $2, etc.,
        are not valid variables. Again, this is only
        for demonstration purposes.*/
        foreach(${$_SESSION['target']} as $p => $v) {
                echo $p.": ".$v."<br />\n";
        }
}

// Define the unique field name for the form, based on Epoch time.
$_SESSION['target'] = "field_".time();

// Adding the brackets after the name will print properly
// in HTML to designate the POST fields as an array.
$html_field = $_SESSION['target']."[]";

?>

<form method="post" action="<?=$_SERVER['PHP_SELF'];?>" />
        Field 1: <input type="text" name="<?=$html_field;?>" /><br />
        Field 2: <input type="text" name="<?=$html_field;?>" /><br />
        Field 3: <input type="text" name="<?=$html_field;?>" /><br />
        <input type="submit" value="Post Now" />
</form>


Thanks a lot!

I have used the method with <form autocomplete="off"> as this method works fine in the browsers I have tested: IE, FireFox and Opera.

If a more specific control over the autocomplete is needed, however, I think your method would provide an excellent solution. In my current project: The autocomplete feature is useful as long as the user works with the same set of exercises, but disturbing when they start on a new set of exercises. If an id that identifies the current set of exercises is given with the url like
http:/.../exercises.php?id=12345
this id could be used while constructing the field names according to your method. Then autocomplete would work as wanted. I will put in on the ToDo-list!

Regards,
Tor

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux