Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Form File Field

by n4mation (Acolyte)
on Sep 01, 2003 at 23:22 UTC ( [id://288203]=perlquestion: print w/replies, xml ) Need Help??

n4mation has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to print stuff from a tab delimitd text file to a html form file field. It duzn't werk!

print "<input type=\"file\" name=\"pic\" value=\"$fields[2]\">";

If I change it to a text field, it werks!

print "<input type=\"text\" name=\"pic\" value=\"$fields[11]\">";

I can't find anything in the search. Could someone give the keywords or an answer?
Thanx 4 yer hep!

Replies are listed 'Best First'.
Re: Form File Field
by bobn (Chaplain) on Sep 01, 2003 at 23:39 UTC

    First, write

    print "<input type=\"file\" name=\"pic\" value=\"$fields[2]\">";
    as
    print qq(<input type="file" name="pic" value="$fields[2]">);
    But don't do that, use CGI.pm. Also, to process a file already on the server, <input type='text'...> is much more suitable. <input type='file'...> is used for file uploads.

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.

Re: Form File Field
by shenme (Priest) on Sep 01, 2003 at 23:40 UTC
    I believe an HTML 'file' form field is input-only, available to the user only for interactions between browser and OS to queue up a file to be sent to the HTTP server on form submission.

    What did you want to accomplish here?

    • simply displaying text of a file?
    • display and allow user to edit text?
    • something else?
Re: Form File Field
by clscott (Friar) on Sep 01, 2003 at 23:51 UTC

    Most browsers do not allow default values in File fields for security reasons.

    Also, you can use alternate quoting methods so that you don't have to escape the double quotes.
    Here are just two examples:

    $field = qq{<input type="file" name="pic" value="$fields[2]">}; or $field = "<input type='file' name='pic' value='$fields[2]'>";
    Clayton --
    Clayton
Re: Form File Field
by TomDLux (Vicar) on Sep 01, 2003 at 23:47 UTC

    A file input field is a mechanism for transfering files from the viewers computer to the server.

    The server does not know what file the user would want to upload, so it does not take initialization values.

    If you could might be a good, simple hack for uploading the password file.

    --
    TTTATCGGTCGTTATATAGATGTTTGCA

Re: Form File Field
by n4mation (Acolyte) on Sep 02, 2003 at 01:15 UTC
    Appreciate the help! I am using it for an edit entry form. I will just use a text field to display it.
      But your text fields all share the same name, 'pic' ... maybe what you want is a radiobutton group:
        <form>
        Foo <input value="foo" type="radio" name="pic" /><br />
        Bar <input value="bar" type="radio" name="pic" /><br />
        Baz <input value="baz" type="radio" name="pic" />
        </form>
      
      Otherwise, your input fields should not share the same name.

      There are a couple of ways to make radio buttons in Perl without to much fuss ... the first is by brute force, much like you did in your question. However, since the "stuff" from your tab delimited file is already stored in the array @fields, we can iterate across the loop and not have to worry about whether or not we are dealing with the second index or the eleventh index:

      print "<form>\n"; for my $field (@fields) { print qq|<input value="$field" type="radio" name="pic" /><br />\n|; } print "</form>\n";
      CGI.pm has a very handy method for generating radio boxes:
      use CGI qw(:standard); print start_form, radio_group(-name => 'pic', -values => \@field), end_form, ;
      I recommend that you visit and read Ovid's online Web Programming with Perl course. You will learn a lot of good stuff there. :)

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://288203]
Approved by phydeauxarff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found