in reply to Pre-Populating an HTML form

Just generate the password, store it in a scalar variable and put it in the textfield in the form.

print '<input type="textfield" value="' . $my_password . '" name="passwordfield"'/>

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: Pre-Populating an HTML form
by dorward (Curate) on Jun 02, 2006 at 10:42 UTC

    It is type "text", not "textfield" (although as "text" is the default, browsers will tend to be able to error correct).

    In Appendix C XHTML you need a space before the "/", but you've added the end of the tag outside of the string anyway.

    print qq{<input type="text" value="$my_password" name="passwordfield" />};

    I'd suggest sticking to HTML 4.01 (which has much better browser support), and using a templating language rather than printing out from the Perl script directly.

      You are of course entirely right on all accounts. I have to make a note to myself not to answer questions before having had my second cup of strong tea (obviously one cup is not enough anymore).

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re^2: Pre-Populating an HTML form
by meinke3 (Acolyte) on Jun 01, 2006 at 21:04 UTC
    Thanks CountZero. What's tripping me up is how to preload the generated password into the form field.

      Well, it all depends on what you have.

      for instance -- if you have SSI (server side includes), you can just do something like:

      <input name='password' value='<!--#include virtual='/cgi/random_password' -->'>

      Another option is to use the whole 'AJAX' concept -- JavaScript to make a call back to the server to ask for a new password, and place it into the field. (of course, then you have a javascript dependancy, and you might as well just do the randomization in JavaScript

      Or, there's the bit that's already been suggested, and just have a CGI to spit out the form. I typically go with this approach, and use the same CGI that generates the backend and initial form, so that I can do data validation, and then re-populate the form, marking any problems.

      Sorry, I misunderstood your question.

      You will have to write a (CGI-)script that dynamically generates the webpage on which is your form. CGI.pm is the archetypical module to do this, but there are many other solutions. Ovid's CGI-course (esp. lesson four and lesson six] will give you a lot of valuable pointers. Personally I tend to use now a templating solution (Template Toolkit) for anything but the most trivial applications, but YMMV.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law