• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 747
  • Last Modified:

HTML SUBMIT (or <a href>) to execute a PHP file without losing focus of current web page

HTML SUBMIT

I want to have a SUBMIT button that does the submit action, but leaves the current page unaltered, so the viewer can continue down it.

The only thing i can think of is using the    TARGET='another_window'
but that changes focus to that window, otherwise seems to work fine.

any suggestions for how to accomplish this?  (i.e.,  executing a PHP routine from clicking a submit (or link) but not disturbing the current page nor current focus.)

thanks


0
willsherwood
Asked:
willsherwood
  • 3
  • 2
  • 2
  • +4
6 Solutions
 
Terry WoodsIT GuruCommented:
Wouldn't that be poor usability, as the user couldn't see any change when Submit is clicked? That sort of behaviour tends to make people click a button multiple times, then give up believing it's broken.
0
 
b0lsc0ttCommented:
You need to look at AJAX then.  I don't recommend using target and opening a new window.  It would look bad.

AJAX uses Javascript, the XMLHTTP object, DOM and server script to dynamically change a page without reloading or refreshing it.  You could submit the form and keep the page.  You would even be able to display the result of the form submission.

There is some good info on AJAX at http://www.w3schools.com/ajax/ajax_example.asp or http://en.wikipedia.org/wiki/Ajax_(programming).  One of my favorite examples and explanations is at http://www.skeymedia.com/programming/classic-asp-and-ajax-tutorial/.

The server language is different but that isn't the important part.  I have liked this PHP example at http://ajax.phpmagazine.net/2005/09/create_ajax_form_with_php.html.

Let me know how this helps or what additional info you need.

bol
0
 
Chris GralikeSpecialistCommented:
You can do this by fetching all the fields and filling them out again. But still as terry sais, depending on the size of the form it might get poor in the performance, and i would even consider using AJAX.

Anywayz, the logic would be something like;

<?php
if(isset($_POST['name']) || isset($_GET['name'])){
       $name = (isset($_POST['name'])) ? $_POST['name'] : $_GET['name'];
}else{
       $name = "";
}

print('
       <p>
       <form action="'.$_SERVER['PHP_SELF'].'" method="POST">
             <input type="text" name="name">'.$name.'</input>
             <input type="submit" name="submit" value="Keep value"/>
       </form>
       </p>
       <p>
          <div>Last Submited value was:'.$name.'</div>
       </p>
       ');
?>

regards,
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ZvonkoSystems architectCommented:
Use target, but set target to an invisibe iframe on the same page.
Like this:

<form TARGET='embeddedIframe' >
<iframe name="embeddedIframe" height="0" width="0" ></iframe>
<input type="submit" >
</form>


0
 
Chris GralikeSpecialistCommented:
Does that actually allow a insertion of data without refreshing? never tried that one....
0
 
willsherwoodAuthor Commented:
sorry for mis-stating the problem.
it's for my own usage, thus usability issues are forgiven...
i'm just trying to solve the focus issue.
i appreciate all the suggestions regarding the other aspects.

if i use an embedded i frame on the same page, won't it re set the focus to the top of the page?

thx
0
 
Michel PlungjanIT ExpertCommented:
Try it and see.
However put the iframe outside the form tags.
0
 
ZvonkoSystems architectCommented:
The location of the iframe does not really matter.  And the window will not change the state at all. It is same as starting a new window as target but the new window does not appear. The actual window does of course change, the iframe gets reloaded and if you would have script to catch that event you can handle even that, but visible does nothing change. It happens nothing.
0
 
ZvonkoSystems architectCommented:
Another trick  to call a PHP side functionality is to create by script an Image() object and assign to image src the URL of your script. But then all parameters has to go by Query_String to PHP. The iframe submit can transport more data and is easier to handle, only submit.

0
 
Michel PlungjanIT ExpertCommented:
I would for some browser's sake
1. change the height and width to 1x1
2. move the iframe outside the form to not break the form elements

With a target, even browsers that do not support iframes, will submit the form to a new window and not break the form (think phone based browsers)
0
 
orbic1Commented:
AJAX - mootools.net -> Demos -> Ajax example. This should sort it for you! Put the JS in the page and use PHP to pass variables as required
0
 
b0lsc0ttCommented:
I'm glad I could help.  Thanks for the fun question, the grade and the points.

bol
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now