Why, if I submit a post form with an iframe as the target, does the value or existence of the submit button not get passed in array $_POST?
I'm working on a simple page to upload an image and I'm having it show a preview of the image before any changes are committed, so I target an iframe because I don't want the page to reload. But targeting an iframe in the form does not pass the submit button. The only difference between the output print_r($_POST, true) show below is if if remove target="hiddenFrame" ind the form tag.
Array
(
[title] => 3
[size] => f3
[type] => 3
[price] => 3
[new] => landscapes
)
Array
(
[new] => landscapes
[title] => 3
[size] => f3
[type] => 3
[price] => 3
[Submit] => 1
)
I don't really need to know the value of the submit button, I was just wondering why this is. This is the first time I've worked with PHP, so any help or clarification would be greatly appreciated. Thanks.
Why is submit button value not in $_POST w/ iframe as target
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Why is submit button value not in $_POST w/ iframe as ta
Why would you do that for an upload...? Unless you handle it with AJAX or Flash, there's little reason not to have the page refresh.gsanaba wrote:I target an iframe because I don't want the page to reload.
Re: Why is submit button value not in $_POST w/ iframe as ta
I'm using ajax, but it is my understanding that you cannot send files, which is why I'm using an iframe as a workaround. The problem arose because I had 2 submit buttons, "preview" and "submit", and I wanted a way to read which button was pushed.superdezign wrote: Why would you do that for an upload...? Unless you handle it with AJAX or Flash, there's little reason not to have the page refresh.
Here's a more simple example with one submit button:
Code: Select all
print print_r($_POST, true);
if ( isset($_POST['submit']))
{
echo 'submit is set';
}
else
echo 'no submit';Code: Select all
<form id="myForm" target="hiddenFrame" action="upload.php" method="POST" enctype="multipart/form-data">
<h3>Select image</h3>
<input type="file" name="userfile" />
<h3>Preview</h3>
<input type="submit" name="submit" value="1" />
</form>
<iframe id="hiddenFrame"
name="hiddenFrame"
style="width:0px; height:0px; border: 0px"
src="blank.html"></iframe>Code: Select all
Array
(
)
no submitCode: Select all
Array ( [submit] => 1 ) submit is set