Page 1 of 1

Why is submit button value not in $_POST w/ iframe as target

Posted: Fri Sep 07, 2007 9:47 pm
by gsanaba
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.

Re: Why is submit button value not in $_POST w/ iframe as ta

Posted: Sat Sep 08, 2007 7:44 am
by superdezign
gsanaba wrote:I target an iframe because I don't want the page to reload.
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.

Posted: Sat Sep 08, 2007 8:43 am
by nickvd
I've found that if you omit the name attribute on the submit button, it won't get sent with the request.

Re: Why is submit button value not in $_POST w/ iframe as ta

Posted: Sat Sep 08, 2007 9:43 am
by gsanaba
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.
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.

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>
with target="hiddenFrame", the output of upload.php is:

Code: Select all

Array
(
)
no submit
when target="hiddenFrame" is removed, the output of upload.php is:

Code: Select all

Array ( [submit] => 1 ) submit is set