missing keys in $_POST
I am trying to get some form data from POST method.
Here's the code of form -
<form action="" method="post" name="form1" id="form1">
<input type="hidden" value="15" name="ad_id">
<table width="100%" cellspacing="0" cellpadding="0" border="0" class="block">
<tbody><tr>
<td valign="top"> </td>
<td align="right">all fields are required</td>
</tr>
<tr>
<td valign="top"> </td>
<td align="center"></td>
</tr>
<tr>
<td valign="top" width="150"><label for="name">Advertisement Name</label>
*</td>
<td><input type="text" 开发者_运维知识库size="45" value="Banner" id="name" name="name">
e.g Home Banner</td>
</tr>
<tr>
<td valign="top"><label for="placement">Advertisement Placement</label></td>
<td><select id="placement" name="placement">
Wide Skyscrapper 160 x 600
</tr>
<tr>
<td valign="top"><label for="code">Advertisement Code</label></td>
<td><textarea rows="5" cols="45" id="code" name="code"></textarea></td>
</tr>
<tr>
<td>Status</td>
<td><label>
<input type="radio" checked="checked" value="1" name="status">
Active</label>
<label>
<input type="radio" value="0" name="status">
Inactive</label></td>
</tr>
<input type="hidden" value="1" name="banner_uploaded" id="banner_uploaded">
<tr>
<td>For Country - </td>
<td>
<select id="country" name="country">
<option>Not posting all the names of country</option>
</select>
</td>
</tr>
<tr>
<td><label for="Scheduling">Valid From </label></td>
<td><input type="text" value="" id="date-from" name="date-from"> Format : dd/mm/yyyy:hh/mm</td>
</tr>
<tr>
<td><label for="Scheduling">Valid Till </label></td>
<td><input type="text" value="" id="date-to" name="date-to"> Format : dd/mm/yyyy:hh/mm</td>
</tr>
<tr>
<td> </td>
<td align="right"><input type="submit" onclick="return validate_ad_form(add_adv)" value="Update Advertisement" class="button" name="update"></td>
</tr>
</tbody></table>
</form>
But I am getting $_POST['code'] empty when I am passing HTML code through it.
When I pass plain text, it works fine.
When I printed $_POST [i.e. used - print_r($_POST) ], I got the following output -
Array ( [ad_id] => 15 [name] => Banner [placement] => ad_468x60 [code] => [status] => 1 [banner_uploaded] => 1 [country] => IN [date-from] => [date-to] => [update] => Update Advertisement )
Please be known, I haven't entered the 'date-from','date-to' fields.
I have entered on purpose as StackOverflow don't allow me to post images!
People,any help will be highly appreciated.
The problem is you're print_r()
is being displayed in a brower. If you've got HTML in your POST data, those tags will be interested as HTML when you dump the data back out. You'll have to force the output into plaintext mode (header('Content-type: text/plain);
), or run the fields which can have HTML in them through htmlspecialchars()
to escape the < and > characters.
If you view the source of the page you're doing the print_r()
on, I suspect you'll see the HTML tags there. If you've only tested with that example.jpg
image, you wouldn't see anything, because that image most likely doesn't exist, so it won't render, and then the <a>
tag has nothing to underline and won't show up either.
精彩评论