Forum Moderators: open

Message Too Old, No Replies

Submit form and follow link in one click

         

posaune02

7:11 pm on Mar 30, 2005 (gmt 0)

10+ Year Member



How would one go about submiting a form AND following a hyperlink?

I've tried:

a href="somepage.php" onclick="document.form.submit();window.location.href=this.href;return false;"

rocknbil

4:52 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think you can, web processes are linear. To do two things at once you'd need two windows, if I'm understanding you correctly.

Why don't you just make the submitted result whatever you want the link to be? Submit form -> server side proccessing -> response redirects to link?

If you **do** need two windows -

function submitForm(form) {
var win = open('link.html');
form.submit();
}

(Shortened for brevity)

posaune02

8:43 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



It's actually kind of complicated. But both the link and the form go to the same place already. The link contains GET data and the form is full of POST stuff. The last thing I tried was to do (onclick="var x=this.href; submit();location=x) also shortened for brevity. But that didn't work either. So now what i'm doing is trying to just merge the GET data that is in the link into the form somehow. The whole thing is for a table (from a database) the form contains the fields the user would like, as well as any search query they want to run. The links are the headers of the tables which are used to sort the current table by the appropriate field. The problem is that the fields are done both with javascript and server side. So checking the checkboxes immediately shows/hides the fields, but it's processed by the server when a search is done that way the current "view" (selected fields) persist on reloads. The problem happens when one sorts the page, because the fields shown are reset back to whatever they were the last time someone runs a query. Thanks for the suggestion though.

mcibor

9:44 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Why don't you use
<input type="hidden" name="get" value="here all the things that you wanted to put through GET">?

It's type that isn't reseted to null after striking key "reset". This way you can pass anything that you wanted to pass through $_GET, and even without escaping the spaces, etc.

Then to get the passed things just use:
echo $_POST["get"];

Best regards
Michal Cibor

posaune02

9:53 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



The problem with that, is that all of the get values (sort1, desc1, sort2, desc2) are all dependant on which link is pressed. At any rate, I got it all finished. It took a fair mixture of javascript and php to do it. The php create the correct javascript function call (similar to how the href values are created- thus dependant on the link) and the javascript takes care of changing the hidden inputs' values. In addition, the links are still active so anyone with javascript disabled will still get functional links to sort (but the viewed fields are simply reset each time). The javascript then returns false so the links aren't followed if javascript is enabled. Thanks for all the help!