You are here: Re: $_POST + spaces and dots in keys « PHP Programming Language « IT news, forums, messages
Re: $_POST + spaces and dots in keys

Posted by maraguida on 12/10/05 04:09

Sergei Riaguzov wrote:
> Consider a test:
>
> wtf.html:
>
> === Cut ===
> <form action="eh.php" method="POST">
> <input type="checkbox" name="many spaces and. . dots. . "/>

Spaces are not allowed in the name of HTML elements.

<quote src="http://www.w3.org/TR/html4/types.html#h-6.2">
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").
</quote>

> <input type="submit" value="Submit">
> </form>
> === Cut ===
>
> eh.php:
>
> === Cut ===
> <?php
> print_r($_POST);
> ?>
> === Cut ===
>
> When we check the checkbox and click the Sumbit button we will see:
>
> Array ( [many_spaces_and____dots____] => on )

Yes, here also.

> It is send to server normally:
>
> many+spaces+and.+.+dots.+.+=on

Yes, here also.

> but in $_POST (or $HTTP_POST_VARS) we see what we see. Any ideas?

I understand the reason the spaces are converted but I do not know why
the points are replaced; you may wnat to try the following if you need
the NAME with the dots and the spaces:

wtf.php (not wtf.html)
=== Cut ===
<form action="eh.php" method="post">
<input type="checkbox" name="<?php echo base64_encode('many spaces
and. . dots. . '); ?>"/>
<input type="submit" value="Submit">
</form>
=== Cut ===

eh.php
=== Cut ===
<?php
print_r($_POST);

$X_POST = array();
foreach ($_POST as $k=>$v) {
$X_POST[base64_decode($k)] = $v;
}
$_POST = $X_POST;
unset($X_POST);

echo "\n\n================\n\n";
print_r($_POST);
?>
=== Cut ===

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация