...

View Full Version : Resolved Is it possible to submit a form and values in a new page/tab?



djm0219
03-28-2009, 09:10 PM
Given the page below I'm trying to have Button 2 submit the form but have the submit and subsequent processing be done in a new page/tab.

The small bit of JavaScript works correctly to open a new page/tab but the form values don't appear to be available in the new page/tab nor does the new page/tab know that Button 2 was pressed.

Is there a method of having a form from a page, along with all of its values and the button that was pressed, available on a new page/tab?



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Form Test</title>
<script type="text/javascript">
function Print_Selected(TheForm) {

PrintWin = window.open(document.getElementById(TheForm).action,'_blank');
PrintWin.focus();
}
</script>
</head>
<body>
<form action="FormTest.php" method="post" id="testform">
<p><input type="submit" name="button1" id="button1" value="Button 1"/>
<input onclick="Print_Selected('testform');return(false);" type="submit" name="button2" id="button2" value="Button 2" /></p>
<p>
<input type="checkbox" name="box1" value="box1" />CheckBox 1
<input type="checkbox" name="box2" value="box2" />CheckBox 2
</p>
</form>
</body>
</html>


FWIW this is a small part of a much larger application and the form and processing are all handled with PHP but the problem is really a basic HTML problem that isn't related to PHP.

twodayslate
03-28-2009, 09:37 PM
http://classicasp.aspfaq.com/forms/how-do-i-submit-forms-to-a-new-window-with-window-open-features.html

djm0219
03-28-2009, 11:56 PM
Thanks for the pointer. A one line change to what I had and presto. Much appreciated.

Actually that's not quite true. The target attribute for a XHTML strict document doesn't support target and without it things don't work as expected. Here's a complete copy of the actual code I'm testing with and it fails if I remove the target attribute from the form tag which I need to do to keep the page XHTML strict compliant.



<?php

if (isset($_POST['button2'])) {
print 'Button 2 was pressed';
exit;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Form Test</title>
<script type="text/javascript">

function Print_Selected(TheForm) {

PrintWin = window.open("",document.getElementById(TheForm).action,'_blank');
var a = window.setTimeout("document."+TheForm+".submit();",10);
document.TheForm.submit();

}
</script>
</head>
<body>
<form action="FormTest.php" method="post" id="testform" target="myNewWin">

<p><input type="submit" name="button1" id="button1" value="Button 1"/>

<input onclick="Print_Selected('testform');return(false);" type="submit" name="button2" id="button2" value="Button 2" /></p>

<p>
<input type="checkbox" name="box1" value="box1" />CheckBox 1
<input type="checkbox" name="box2" value="box2" />CheckBox 2
</p>
</form>
</body>
</html>

djm0219
03-29-2009, 04:41 PM
Thanks to a friend of mine a solution which allows the page to remain XHTML strict compliant is included below in case someone else comes along looking for a similar solution. I was making it more complicated than it needed to be.



<?php

if (isset($_POST['button1'])) {
print 'Button 1 was pressed';
print '<p><a href="FormTest.php">Back</a>';
exit;
}

if (isset($_POST['button2'])) {
print 'Button 2 was pressed';

if (isset($_POST['box1'])) {
print '<p />Checkbox 1 was selected';
}

print '<p><a href="FormTest.php">Back</a>';
exit;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
<title>Form Test</title>
<script type="text/javascript">

function Print_Selected(BatchForm) {

document.forms[BatchForm].target='batchprint';
document.forms[BatchForm].submit();
return false;

}

</script>
</head>
<body>
<form action="FormTest.php" method="post" id="testform">

<p>

<input type="submit" name="button1" id="button1" value="Button 1"/>
<input value="Button 2" onclick="Print_Selected('testform');" name="button2" type="submit" />

</p>
<p>
<input type="checkbox" name="box1" value="box1" />CheckBox 1
<input type="checkbox" name="box2" value="box2" />CheckBox 2
</p>
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum