in reply to Re: cgi question - using an image button for filefield
in thread cgi question - using an image button for filefield

Doesn't look elegant at all, is there no other way to do this kind of thing?
Thanks,
Jonathan
  • Comment on Re^2: cgi question - using an image button for filefield

Replies are listed 'Best First'.
Re^3: cgi question - using an image button for filefield
by martymart (Deacon) on Nov 15, 2004 at 14:55 UTC
    Hi Jonathan,

    How about something like this, uses a bit of scripting instead of all that css stuff:
    #!/usr/bin/perl -w use strict; use warnings; use CGI; use CGI::Carp qw(fatalsToBrowser); #errors will show in the browser my $co=new CGI; print $co->header, $co->start_html( -title=>'fileupload.cgi', -BGCOLOR=>'#FFFFFF', ), $co->start_form( -method=>'POST', -name=>"myForm", -action=> "http://localhost/cgi-bin/fileupload2.cgi", ), $co-> filefield( -name => 'browse', -style => 'display:none' ), $co-> textfield( -name => 'file', ), "&nbsp;&nbsp;&nbsp;&nbsp;", "<a href=\"#\" onClick=\"document.forms[0].browse.click();document.for +ms[0].file.value=document.forms[0].browse.value;return false;\">", "<img name=\"browse\" src=\"http://localhost/html/browse.bmp\" alt=\"b +rowse\" border=\"0\"></a>", $co->p, $co->image_button( -name => 'submit', -src => 'http://localhost/html/add.bmp', -value => "Submit", -onclick => "document.forms[0].browse.disabled=tru +e;document.forms[0].submit()", ), $co->end_form(), $co->end_html; exit 0;
    I've tried this myself and it does appear to work.
    Enjoy,
    Martymart