Jump to content
phppup

PHP in multiple new windows

Recommended Posts

I have a form  with three submit buttons that ALL have the same action="process. php"

Each submit has a different value to query a database table which provides the requested information.

Button 1 value = baseball team

Button 2 value = football team

Button 3 value = hockey team

Currently, a submission will process and provide information of the team members for the sport that is selected.

I have decided it might be nice to retrieve the data in separate windows for easy side by side comparison.

Using<form action="process. php"  onsubmit="window.open('about:blank','print_popup','width=1000,height=800');"> 

I have been able to get data to populate in a newly opened window. But the data continues to re-populate the same window.

How can I get 3 independent NEW WINDOW to open so they can be compared side by side?
 

 

 

 

 

Share this post


Link to post
Share on other sites

I'd do the data gathering via AJAX, then open the modal window using JavaScript once the AJAX response payload has been delivered. Right now you're sending the form data to process.php while trying to pop open a new window with no actual data attached.

Share this post


Link to post
Share on other sites
Posted (edited)

I'm popping open process. php which will populate the data the same way that it does when it opens as a standard PHP page.

Edited by phppup

Share this post


Link to post
Share on other sites

I could well be wrong (as I said I'd just do it via AJAX and open the popup on data return), but I'm not sure you're actually doing what you think you're doing. Check the documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window/open

The first parameter to the window.open() call is URL - you're passing 'about:blank' as the URL and sending your form to process.php. Two different addresses, two different actions.

Share this post


Link to post
Share on other sites

I seem to be getting an acceptable result, sort of.

I believe at this point the problem is more with the "target" because I on placing results for submitting 1,2, or 3 on the same target.

If I submit with button 1, a valid result opens in a new window. If I then submit with button 2, the SAME "new window" repopulates and updates with data associated to that query.

I am currently unable to get a second "new window" to open for a side by side comparison of on screen data.

I was thinking of using JS to alter the name of the "target" so I could hopefully evade the conflict in that manner.

But not having much luck there either.

 

Share this post


Link to post
Share on other sites
4 minutes ago, phppup said:

If I submit with button 1, a valid result opens in a new window. If I then submit with button 2, the SAME "new window" repopulates and updates with data associated to that query.

Read the documentation maxxd linked until you find out why it's behaving that way.

Share this post


Link to post
Share on other sites

I've read the link.

It seems to indicate in the first section that leaving the windowName empty will cause new windows to be opened, yet that does not seem to be the case.

is this bc I'm using chrome at the moment (I would think not).

so what am I doing wrong?

I've read the link.

It seems to indicate in the first section that leaving the windowName empty will cause new windows to be opened, yet that does not seem to be the case.

is this bc I'm using chrome at the moment (I would think not).

so what am I doing wrong?

Share this post


Link to post
Share on other sites

Or perhaps I am misunderstanding.

When the link states: 

If the string is empty, the browser will create a new window every time

are the statement meant to indicate "... Everytime that a singular new window is opened" but that once opened, it will forever be pointed to until closed?

Or does everytime meet my goal, which is to open a new window everytime a submit button is clicked???

So confused now.

 

Share this post


Link to post
Share on other sites

You can do what you want by dynamically setting the form's target as you had guessed.  I've done this a few times in the past to submit a form into a popup window.

For example:

<form action="https://aoeex.com/datetime.php" target="_blank" id="theForm">
<ul>
    <li><button type="submit" name="which" value="first">First button</button></li>
    <li><button type="submit" name="which" value="second">Second button</button></li>
    <li><button type="submit" name="which" value="third">Third button</button></li>
</ul>
</form>
var $form = $('#theForm');

$form.find('button').click(function(e){
    var target = $(e.target);
    var windowName = target.val();
    window.open('', windowName, 'width=450,height=100,scrollbars,resizable');
    $form.attr('target', windowName);
});

It's not possible to detect which button submitted a form during the submit handler so you have to instead attach your event listener to each button.  In the click handler you can open your new window with an appropriate window name and then set the form's target attribute to that name.

If a popup blocker stops your window.open from functioning then your form will instead open in a new tab/full window due to the target attribute.

Share this post


Link to post
Share on other sites

Thanks KICKEN.

I came up with something similar at 2:AM this morning, which uses Javascript in a shoddy kinda way, but looked as if it would get the job done.

This seems like an excellent alternative to weigh in contention, and looks as if it too, would do EXACTLY what I am attempting to accomplish.

Thanks again.

Share this post


Link to post
Share on other sites

Not gonna lie, I didn't realize attaching a target attribute to a form would do anything at all...

There's obviously nothing wrong with your response kicken, but personally (just for readability if nothing else) I'd still seriously consider doing this via AJAX and opening the modal after the processing script returns the data, using a data-{whatever} attribute on the buttons to tell the processing script which logic branch to follow. I have, however, been accused of working harder than I work smart sometimes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.