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

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

 



On Jan 21, 2008 10:31 AM, Tor Vidvei <tor.vidvei@xxxxxxxx> wrote:
> I'm developing a traning page for basic math.  The answers are entered by
> the user in simple text input fields and the same page is returned (after
> having been processed by php) to the user with indications of correctness
> or error on each answer.  If the AutoComplete feature is turned on a
> droplist with previous entries are displayed in the answer fields, even if
> new exercises are generated.  This is quite distracting.  Is there any way
> I can block this feature from my php-code, even if it is turned on in the
> users browser?

    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>

-- 
</Dan>

Daniel P. Brown
Senior Unix Geek and #1 Rated "Year's Coolest Guy" By Self Since
Nineteen-Seventy-[mumble].

-- 
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