Evening all, first post so be nice ;)

I want to know if it is possible to show the results of a form in a new window. So when you press the submit button on a post or get type of form, how do you get it to show the results in a new page?

I can post code if you want to but i think there is enough to go on.

Thanks and look forward to helping out too...

IK

Dani AI

Generated

A few practical options, building on and but filling gaps they did not show.

A simple HTML route is the form-level target (as noted). For finer control, use the HTML5 submit-level attribute formtarget on a button so the same form can open results either in-place or in a new window/tab without changing the form element itself:

<form action="/show-results" method="post">
  <input name="q">
  <button type="submit">Show here</button>
  <button type="submit" formtarget="resultsWindow">Open in new window</button>
</form>

For a POST that needs to open a dedicated window and avoid the opened page manipulating the opener, open the window from the user event, sever opener, set the form target to the window name, then submit. This keeps popup blockers from blocking the window (it was opened during the click) and removes the window.opener attack surface:

<script>
function openAndSubmit(form){
  var w = window.open('', 'resultsWindow', 'width=800,height=600');
  try { w.opener = null; } catch(e) {}
  form.target = 'resultsWindow';
  form.submit();
}
</script>

<form action="/show-results" method="post" onsubmit="openAndSubmit(this); return false;">
  <input name="q">
  <input type="submit" value="Submit">
</form>

Notes and troubleshooting: using GET will expose values in the URL (easy to debug). POST requires server-side handling (PHP/ASP/etc.) to echo or render the response (what and mentioned). Popup blockers often block windows opened outside a user gesture. For UX, opening new windows should be used sparingly — consider in-page results or a modal as a more modern choice.

Recommended Answers

All 8 Replies

Can be done in php, when yuo name the form's field, then you can export that as a $name variable.

Welcome to TTF! :cool:

The easiest way is to submit the form to target="_blank" - here's some sample code in HTML/PHP. The PHP code is just so the form doesn't get displayed:

<?
 if(isset($_POST['something'])) {
  echo $_POST['something'];
 }
 else {
  echo '
   <form action="'.$_POST['SCRIPT_NAME'].'" method="post" target="_blank" >
	Input Something: <input type="text" name="something">
	<input type="submit" value="Submit">
   </form>';
 }  
?>

Any questions, just ask.

Thanks for the welcome guys and a successful one at that.

I didnt realise you could use the target variable in the form tag.

Thanks!

Can be done in php, when yuo name the form's field, then you can export that as a $name variable.

Hmm? What do you mean? What's the other way to do it? I can't think of any right this minute, so maybe you can clear it up. :cool:

<form action=page.php method=post>
<input type=text name=var>
<input type=text name=var2>
</form>

You could export the content of that form as $var and $var2.

How does that open up a new window and display the variables submitted? Sorry, not trying to be a dick about it, just not following.

Greetings.
How about using Javascript alone?
Is it possible to show the results of a form in a new window?
I have seen how things were done using Request.QueryString by decoding the url. But is there other alternative similar to the ASP's Request.Form("element") way? I'm trying to avoid using ASP, because the server doesn't have IIS. Please help.

<?php if(isset($_POST['field1')){ 
if(isset($_POST['field2'])) { 
/* validate field values  
 if values acceptible
 connect to database 
 update database 
 set disabled flag ($disabled = true ) to prevent resubmission */ } } ?>
<form action='<?php echo $_server['PHP_SELF']; ?>' method='post'>
<input type='text' name='field1' value='<?php if(isset($_POST['field1'] {echo $_POST['field1'];} ?>' /><br />
<input type='text' name='field2' value='<?php if(isset($_POST['field2'] {echo $_POST['field2'];} ?>' /><br />
<input type='submit' value='whoopdiedoo' <?php if(isset($disabled) {echo 'disabled="disabled"';} ?>/></form>

incomplete code scrap
Form submits to itself displays the values submitted in the form (very messy code but its ONLY a sample of what can be done)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.