in reply to y username is empty

What was wrong with this thread on the same topic? http://perlmonks.org/index.pl?node_id=934189

Your code above doesn't match your question, since the $pxuser stuff is commented out and it doesn't involve the parameter key 'pusr' at all. And in one of your replies here, you're talking about 'p_usr' again. I realize you don't know Perl, but you're going to have to be more specific and pay more attention to the details if you expect to get this working (or pay a Perl programmer).

Questions for you to answer to help us help you:

  1. How are you getting the value you expect to be in $pxuser? Show the code that does that.
  2. What does the HTML that provides that field look like?
  3. Are any errors showing up in your browser or your server's error log?

Replies are listed 'Best First'.
Re^2: y username is empty
by sasidhardv (Initiate) on Oct 31, 2011 at 06:49 UTC
    function setval() { var url = window.location.toString(); url.match(/\?(.+)$/); var params = RegExp.$1; var params = params.split("&"); var queryStringList = {}; for(var i=0;i<params.length;i++) { var tmp = params[i].split("="); var acc_usr=tmp[1]; document.getElementById('pusr').value = acc_usr; } } <body onload = "setval();"> <FORM ENCTYPE="multipart/form-data" ACTION="/cgibin/fupload.cgi" METHO +D="POST"> <TABLE BORDER=0 WIDTH="550"> <TR> <TD ALIGN=RIGHT> File Name: </TD> <TD> <INPUT TYPE="File" NAME="filetoupload01" SIZE="70"> </TD> </TR> <TR> <TD COLSPAN=2>&nbsp;<BR></TD> </TR> <TR> <TD ALIGN=RIGHT> <INPUT TYPE="Submit" onclick="ValidateFilename(filetoupload01.value)" +VALUE="UPLOAD FILE"> <INPUT TYPE="HIDDEN" NAME="filetoupload02" VALUE=""> </TD> <TD ALIGN=RIGHT > <INPUT TYPE="RESET" VALUE="RESET FORM"> <INPUT TYPE="hidden" name="pusr" value="" /> </TD> </TR> </TABLE> </FORM> </body>

    the following is the code in fupload.cgi

    my %ufiles; foreach $key (sort {$a <=> $b} $query->param()) { next if ($key =~ /^\s*$/); next if ($query->param($key) =~ /^\s*$/); next if ($key !~ /^filetoupload_(\d+)$/); $Number = $1; if ($query->param($key) =~ /([^\/\\]+)$/) { $Filename = $1; $Filename =~ s/^\.+//; $ufiles{$Number} = $Filename; $File_Handle = $query->param($key);

    i want to read the value of pusr thats coming from the html form and rename the uploaded file with the name of pusr value hope i am clear now :)

      Well, it's clearer, but wow, this is some messy stuff. Ok, so there's a hidden field named 'pusr' that starts out with the value "". Then some pretty sketchy-looking javascript takes the URL of the page, breaks it up by splitting it on &, then breaks up each part of that by splitting on =, and for each of those, assigns the second half as the value of the hidden field named 'pusr'. (But see my last paragraph for why it doesn't actually do that either.)

      So if the URL is something like http://example.com/index.pl?type=search&user=john, then first it'll set 'search' as the value of the 'pusr' field, and then it'll assign 'john' as the value. So what gets assigned will be the value of the last pair in the URL.

      Since we don't know the URL, we can't really diagnose any further here. My next step (short of scrapping all this and starting over) would be to put an alert after the document.getElementByID line, so you can see what's being assigned. Something like alert(acc_usr);. That'll show you how many values are being extracted from the URL, and which is the last one found.

      Oh, and there's another problem: getElementById is looking for an element with id='pusr', but there isn't one, so that assignment does nothing (except maybe throw a javascript exception). There's a difference between name='pusr' and id='pusr', so you may want your hidden field to have both.