473,321 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

method="POST" changes '.' to '_'

I am trying to use POST to transfer data to another page. When I do
this, '.' characters get converted to"_". For example:

#index.html:
<form action="test.php" method="post">
<input type="submit" name="filename.txt">
</form>

#test.php
<html>
<?php
var_dump( $_POST );
?>
</html>

This displays:

array(1) { ["filename_txt"]= string(12) "Submit Query" }

ie 'filename.txt' is changed to 'filename_txt'
How can I stop this behaviour?

Jul 6 '06 #1
14 2217
On 6 Jul 2006 15:07:59 -0700, "Robert S" <ro**********************@gmail.com>
wrote:
>I am trying to use POST to transfer data to another page. When I do
this, '.' characters get converted to"_". For example:

#index.html:
<form action="test.php" method="post">
<input type="submit" name="filename.txt">
</form>

#test.php
<html>
<?php
var_dump( $_POST );
?>
</html>

This displays:

array(1) { ["filename_txt"]= string(12) "Submit Query" }

ie 'filename.txt' is changed to 'filename_txt'
How can I stop this behaviour?
You'd have to patch PHP.

See main/php_variables.c, php_register_variable_ex
(line 92 in PHP 5.1.4):

/* ensure that we don't have spaces or dots in the variable name (not binary
safe) */
for (p = var; *p; p++) {
if (*p == ' ' || *p == '.') {
*p='_';
} else if (*p == '[') {
is_array = 1;
ip = p;
*p = 0;
break;
}
}
var_len = p - var;

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 6 '06 #2
I am trying to use POST to transfer data to another page. When I do
this, '.' characters get converted to"_". For example:
You'd have to patch PHP.
Thanks for the speedy answer.

Is there another way? I'm using debian on a work PC and am extremely
reluctant to do any patching.

Jul 6 '06 #3
*** Robert S escribió/wrote (6 Jul 2006 15:34:38 -0700):
Is there another way? I'm using debian on a work PC and am extremely
reluctant to do any patching.
Why don't do simply perform some sort of encoding and decoding, like
bin2hex() or base64_encode() or even a custom one?

--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
--
Jul 6 '06 #4
On 6 Jul 2006 15:34:38 -0700, "Robert S" <ro**********************@gmail.com>
wrote:
>I am trying to use POST to transfer data to another page. When I do
this, '.' characters get converted to"_". For example:
You'd have to patch PHP.

Thanks for the speedy answer.

Is there another way? I'm using debian on a work PC and am extremely
reluctant to do any patching.
If you're brave, then there's $HTTP_RAW_POST_DATA, but since you'll then have
to do your own POST-data decoding then beware of getting it wrong.

Just going back to your original post:
<form action="test.php" method="post">
<input type="submit" name="filename.txt">
</form>
Are you committed to this layout? "filename.txt" can exist fine as a value,
it's just as a name it's a problem. Can you not send the filename over as a
value in an input type=hidden field, for example?

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 6 '06 #5
umm why dont you just (on the test.php page) do a str replace and
change the '_' back to a '.' ??

flamer.

Robert S wrote:
I am trying to use POST to transfer data to another page. When I do
this, '.' characters get converted to"_". For example:

#index.html:
<form action="test.php" method="post">
<input type="submit" name="filename.txt">
</form>

#test.php
<html>
<?php
var_dump( $_POST );
?>
</html>

This displays:

array(1) { ["filename_txt"]= string(12) "Submit Query" }

ie 'filename.txt' is changed to 'filename_txt'
How can I stop this behaviour?
Jul 6 '06 #6
>
Why don't do simply perform some sort of encoding and decoding, like
bin2hex() or base64_encode() or even a custom one?
Thanks. That looks like the best idea. Fortunately the program that
creates the files seems to give the files "safe" filenames, except for
the '.' with the extension. I might just trim off the extension and
add it at the other end. bin2hex also looks promising.

Jul 6 '06 #7
Geoff wrote:
On 6 Jul 2006 16:03:14 -0700, flamer di******@hotmail.com wrote...
>>umm why dont you just (on the test.php page) do a str replace and
change the '_' back to a '.' ??

flamer.


Thought about that too, but could have a problem with

<input type="submit" name="file_name.txt">

becoming "file.name.txt", if other form fields are using that logic.

Saw someone else (Andy?) mention the "name" being the problem and not the value.
Instead of messing around with the ".txt", name it "filename" and append a
".txt" later if it's that crucial to the program.
Geoff
Geoff,

Remember - the name attribute is just something for you to identify the
data when it's passed. It does not have to be an actual filename - it
could be "xyz" for that matter. But it HAS to be changed, because '.'
is not a valid character in a PHP variable.

Whatever you have here is the identifier in the $_POST or $_GET array,
i.e. $_POST['xyz'].

The value in the field is where you want "filename.txt", and that should
not be changed.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 7 '06 #8
Robert S wrote:
<form action="test.php" method="post">
<input type="submit" name="filename.txt">
</form>
Why are you even passing the filename in a button's name?

Why not:

<form action=test.php method=post>
<div>
<input type=hidden name=myfile value="filename.txt">
<input type=submit>
</div>
</form>

??

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Jul 7 '06 #9
Why are you even passing the filename in a button's name?
>
Why not:

<form action=test.php method=post>
<div>
<input type=hidden name=myfile value="filename.txt">
<input type=submit>
</div>
</form>
The page is a fax client that allows large numbers of files to be faxed
off to multiple recipients. I have a whole lot of buttons and text
inputs that refer to different files. The receiving page loops through
$POST and identifies the file that the button refers to. All text
inputs and checkboxes etc need to be sent to the receiving page, so I
can't use multiple <formelements. The example I gave was just an
illustrative example - its not from my code. As far as I can see this
seems to be the only way of doing it. The files are .PDF files created
by cups-pdf - so they are FULL of underscores. If I use an <a href>
tag, the POST variables don't get sent to the receiving page.

bin2hex looks like the way to go.

Jul 7 '06 #10

Robert S wrote:
Why are you even passing the filename in a button's name?

Why not:

<form action=test.php method=post>
<div>
<input type=hidden name=myfile value="filename.txt">
<input type=submit>
</div>
</form>

The page is a fax client that allows large numbers of files to be faxed
off to multiple recipients. I have a whole lot of buttons and text
inputs that refer to different files. The receiving page loops through
$POST and identifies the file that the button refers to. All text
inputs and checkboxes etc need to be sent to the receiving page, so I
can't use multiple <formelements. The example I gave was just an
illustrative example - its not from my code. As far as I can see this
seems to be the only way of doing it. The files are .PDF files created
by cups-pdf - so they are FULL of underscores. If I use an <a href>
tag, the POST variables don't get sent to the receiving page.

bin2hex looks like the way to go.
In my mind if you cannot avoid having those periods in the form-fields,
you have a design problem in your code. For example:

<input type="hidden" name="filename1" value="filename1.txt">
<input type="submit" name="SubmitStuff1">

<input type="hidden" name="filename2" value="filename2.txt">
<input type="submit" name="SubmitStuff2">

With this kind of stuff on the target page you get the filename by:

if( isset($_POST["SubmitStuff1"])) {
$MyFilename = $_POST["filename1"];
}

or

for($i=0;$i<100;$i++) {
if(isset($_POST["SubmitStuff".$i)) {
$MyFilename = $_POST["filename".$i];
}
}

and so forth. You never really need a period in the field name, unless
the form is produced by some other software, generator, or some
framework, but these are other issues then.

Jul 7 '06 #11
Robert S wrote:
>>Why are you even passing the filename in a button's name?

Why not:

<form action=test.php method=post>
<div>
<input type=hidden name=myfile value="filename.txt">
<input type=submit>
</div>
</form>


The page is a fax client that allows large numbers of files to be faxed
off to multiple recipients. I have a whole lot of buttons and text
inputs that refer to different files. The receiving page loops through
$POST and identifies the file that the button refers to. All text
inputs and checkboxes etc need to be sent to the receiving page, so I
can't use multiple <formelements. The example I gave was just an
illustrative example - its not from my code. As far as I can see this
seems to be the only way of doing it. The files are .PDF files created
by cups-pdf - so they are FULL of underscores. If I use an <a href>
tag, the POST variables don't get sent to the receiving page.

bin2hex looks like the way to go.
If you don't mind assuming that javascript is on then:

one of these:
<input type='hidden' name='myfile' value='' />

and many of (assuming form's name is 'myform'):
<input type='submit'
onclick='document.myform.myfile.value="filename.tx t"' />

-------------------------------------------------
Alternatively, assuming the buttons have the filename as their text,
just have many:

<input type='submit' name='myfile' value='filename1.txt' />
<input type='submit' name='myfile' value='filename2.txt' />
<input type='submit' name='myfile' value='filename2.txt' />
....

then $_POST['myfile'] should be the value field of the clicked submit
button.
Jul 7 '06 #12
Both of these suggestions look good. I'm using javascript already and
that looks like the most elegant method.

Jul 7 '06 #13
Robert S wrote:
>>Why are you even passing the filename in a button's name?

Why not:

<form action=test.php method=post>
<div>
<input type=hidden name=myfile value="filename.txt">
<input type=submit>
</div>
</form>


The page is a fax client that allows large numbers of files to be faxed
off to multiple recipients. I have a whole lot of buttons and text
inputs that refer to different files. The receiving page loops through
$POST and identifies the file that the button refers to. All text
inputs and checkboxes etc need to be sent to the receiving page, so I
can't use multiple <formelements. The example I gave was just an
illustrative example - its not from my code. As far as I can see this
seems to be the only way of doing it. The files are .PDF files created
by cups-pdf - so they are FULL of underscores. If I use an <a href>
tag, the POST variables don't get sent to the receiving page.

bin2hex looks like the way to go.
OK, no problem. Just:

<form action=test.php method=post>
<input type=hidden name="filename[0]" value="filename.txt">
<input type=submit name="Submit[0]">
<input type=hidden name="filename[1]" value="filename.pdf">
<input type=submit name="Submit[1]">
<input type=hidden name="filename[2]" value="filename.doc">
<input type=submit name="Submit[2]">
<input type=hidden name="filename[3]" value="filename.html">
<input type=submit name="Submit[3]">
</form>

File names are in $_POST['filename[0]'], $_POST['filename[1]'], etc.
The button which was pressed will be in $_POST['Submit[x]'].

Simply loop through the Submit array to find which one was pressed with
isset(), and pick the appropriate file from the filename array.

Expandable, easily programmed and requires no JS.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 7 '06 #14
>
OK, no problem. Just:

<form action=test.php method=post>
<input type=hidden name="filename[0]" value="filename.txt">
<input type=submit name="Submit[0]">
<input type=hidden name="filename[1]" value="filename.pdf">
<input type=submit name="Submit[1]">
<input type=hidden name="filename[2]" value="filename.doc">
<input type=submit name="Submit[2]">
<input type=hidden name="filename[3]" value="filename.html">
<input type=submit name="Submit[3]">
</form>

Simply loop through the Submit array to find which one was pressed with
isset(), and pick the appropriate file from the filename array.
I've gone for this approach. Works a treat. Many thanks for the help
folks.

Jul 7 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Herbert Piljer | last post by:
Wenn ich versuche ein Formular zu versenden bekomme ich als Absender immer Resource.id.#5@mailserver.de. Folgendes Script wird verwendet: <?php include ("syndbopen.php"); $email=...
7
by: Rui Pestana | last post by:
Hello all, I want to use the POST method to submit the form and then grab the parameters in the asp file with request.form("parm"). The problem is that I am using the _search target to open...
0
by: Billy Boone | last post by:
I have a current web application that utilizes a login to authenticate users into the application. Once I authenticate them, I store away the user's name in a Session variable. I then utilize...
0
by: Joeyej | last post by:
Hi - I'm trying to move/use a web form (containing some javascript field checks) previously hosted on a Windows 2000 server. However, the FORM METHOD="post..." command in the form (shown below)...
2
by: ReGex | last post by:
I have been working on a little project in C# to log into a website (using code inspired/riipped from http://www.codeproject.com/cs/internet/bloglivejournal.asp) but when I request the response,...
1
by: Jim Carlock | last post by:
Let's not argue about semantics. Let's talk about semasiology. Do specifications exist for using mixed case, upper case, lower case for the contents of the method employed? My own preferences...
25
by: william.hooper | last post by:
here is my form: <html> <head></head> <body> <FORM ACTION="code.php" method="post"> <INPUT TYPE=SUBMIT NAME="arty.jpg" VALUE="Action"> </FORM>
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.