1

I have inherited a system running on PHP4.4.9, however I'm needing to do something that requires 5.0 or higher, at current we cannot upgrade as it's part of a "package" (Hornbill Supportworks) that will break various feature and functionality. What I have done is added the php 5+ stuff to my personal webspace for now. An example of the form I have is:

<form action="./ChangeStatusSubmit.php" method="post" name="main">
<input type="text" size="15" maxlength="43" name="GappsMailTextS">
<button type="submit">
Submit status changes
</button>
</form>

In the form action I'm also wanting it to post to http://www.externalurl/test.php, can anyone help with this? I've not found anything that works online as it requires "curl" or ajax (I've never used/seen ajax so I would have no idea how to put that in to the file! any help appreciated.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Maff
  • 441
  • 1
  • 6
  • 27
  • curl or ajax is the truth.. – Nouphal.M Jan 20 '14 at 14:22
  • I'm curious to know what you need to do that requires PHP5. There's little that you can't do in PHP4 - it just takes a little more effort sometimes. –  Jan 20 '14 at 14:29
  • @MikeW It's a status update page where we update a page when our systems go up/down so our users can see, php5 comes in as we also want to tweet the update text we put out to them. The only way I can find to tweet is to use php5 – Maff Jan 20 '14 at 14:52
  • Can't you just include your test file in the other file or make a separate form for testing purposes as you have done with the test file? – Adsy2010 Jan 20 '14 at 15:14
  • @Adsy2010, no, one file lives on our network (ChangeStatusSubmit.php) and is on the server with php4, the other is on my webspace (test.php) which uses php5 which is what it requires to work, both work in their own right, just need them both to be submitted to at the same time. – Maff Jan 20 '14 at 15:24

3 Answers3

1

Forms generally only post to one URL, because in general terms, a POST is no different than a GET, in that a browser asks a server for a URL and displays the result. (The only actual difference lies in where the input data is placed in the HTTP request, beyond the scope of this answer).

One approach would be to have the first server (the host for the form's action) send the data on to the second server and, if needed, incorporate the second server's response in the output sent back to the browser.

Brian A. Henning
  • 1,374
  • 9
  • 24
0

You need to use AJAX for this. There isn't way to add two actions to the form. You can ajax your first action and then submit the declared form action in .done handler. Hopefully you have jquery, it's lot more difficult to use plain js for ajax.
Some links:
http://api.jquery.com/jquery.ajax/#example-0
How to make an AJAX call without jQuery?

So based on above examples the jquery solution could be this:

$('form[name=main]').submit(function() {
  return false;
  $.ajax({
    type: "POST",
    url: "http://www.externalurl/test.php",
    data: { GappsMailTextS: $('input[name=GappsMailTextS]').value() }
  })
  .done(function( msg ) {
    $('form[name=main]').submit();
  });
)};
Community
  • 1
  • 1
aksu
  • 5,221
  • 5
  • 24
  • 39
  • This will fail due to the `same origin` security policy in place in the browser. A JSONP request or a CORS header on the second target site might get around this. –  Jan 20 '14 at 14:27
  • @aksu we do have jquery, yes, I've never touched AJAX before, how do I put that within a php page? does it go within – Maff Jan 20 '14 at 14:33
  • Yes, @Maff. You need to place this code to `script` tags in your `head` part. – aksu Jan 20 '14 at 15:35
0

As @aksu posted, AJAX is one tool that you can use to solve this problem.

However, if you want it to be processed as a form submission to two different servers, there is something else that might work for you.

The action attribute on the form tells where the form should be posted to. I think that you should be able to use Javascript to submit the form to one server, then modify the form so that the action attribute points to a different server, and then submit it again.

I'm not certain but you may also need to modify the target attribute to tell the browser not to open the new page in the same window as that could stop your Javascript.

Vivian River
  • 31,198
  • 62
  • 198
  • 313