Reputation: 57
I have the following php code in my input field:
<input type="submit" name='<?php echo $row["date"];?>' value="send">
a var_dump($row["date"])
shows the data is a string like so:
string '2015-10-03 19:01:47' (length=19)
Why then, when I post this form, does the blank space get automatically replaced by an underscore and how can I avoid that?
var_dump($_POST)
:
array (size=1)
'2015-10-03_19:01:47' => string 'send' (length=4)
Upvotes: 1
Views: 1716
Reputation: 11171
As @arkascha has explained in his comment.
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 (".").
So it is not possible to have space as a name. You asked how to avoid this one? Simple, just don't use the date as the name of the input. You can have hidden input field that hold the date value.
<input type="hidden" name='date' value='<?php echo $row["date"];?>'>
<input type="submit" name='submit' value="send">
Alternatively, you can use <button>
<button type="submit" name="submit" value="<?php echo $row["date"]; ?>">Submit</button>
Upvotes: 1
Reputation: 16782
and how can I avoid that?
You can use str_replace
to get the desired behavior:
<?php
$send = '2015-10-03_19:01:47';
echo str_replace("_"," ",$send);
?>
OUTPUT:
2015-10-03 19:01:47
Upvotes: 1