[Solved] Posting to multiple URLs through one form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

[Solved] Posting to multiple URLs through one form

Post by mjseaden »

Dear All

I have a data form. On this data form are a variety of text INPUT objects, as well as a few FILE objects.

Also on this page are 'Preview Post', 'Clear Form', 'Submit Form' and 'Upload Pictures' buttons, each of which need the information contained within the form.

However, using the ACTION parameter for the form, I can only stipulate one target URL for any submit buttons embedded in the form.

I want to be able to use the image buttons (Preview, Clear, Submit, Upload) described above to go to their corresponding URLs, but also for those URLs to receive the corresponding POST information from the data form.

Seeing as I can only use one URL through stipulating the ACTION parameter in the FORM, how can I post the information on the forms to each of those URLs separately?

I hope that's clear.

Many thanks

Mark
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

In case that isn't clear, maybe this will help:

Code: Select all

<FORM METHOD="post" ACTION="???.php">
<INPUT TYPE="text" LENGTH="3">
<INPUT TYPE="text" LENGTH="10">
<INPUT TYPE="file">
<A HREF="preview.php"><IMG SRC="preview.jpg"></A>
<A HREF="clear.php"><IMG SRC="clear.jpg"></A>
<A HREF="submit.php"><IMG SRC="submit.jpg"></A>
<A HREF="upload.php"><IMG SRC="upload.jpg"></A>
</FORM>
I want to be able to POST the contents of those INPUT objects to either preview.php, clear.php, submit.php or upload.php, depending on the user's requirements. However, with only 1 URL able to be given for the form's ACTION parameter, and with the INPUT objects containing text too large to simply be transferred through the URL via the usual url.pjp?text=hello&text2=goodbye, how do I post the information to those different URLs depending on what button the user clicks on?

It seems quite a conundrum for quite a basic need.

Many thanks

Mark
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Those JPGs are button pictures for the links by the way - image buttons.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

You have posted three separate times on the same subject, which is not very polite. Nonetheless:

Item one. This creates a "submit" button using an image. A form may have as many as you like, each with a different "Name" property. Image can be a jpeg.

Code: Select all

&lt;INPUT TYPE=image src="ab_add.gif" Name="Page1"&gt;
A click on that button/image will result in a POST var in the resolving form of Page1.x and Page1.y which PHP resolves to Page1_x and Page1_y, so:

Code: Select all

<?php
if (isset($_POST['Page1_x']))
{     header("Location:Page1.html");   // or whatever
      exit;
}                    // repeat for each button/page conbination
?>
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Hi - sorry about the multiple entries. I normally assume that if an item gets more than 10 rows down the line, it will be forgotten. Additionally to this, I reworded my explanation to that it was clearer what I was talking about.

Sorry for any inconvenience and thanks for the help.
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post by Bill H »

From your other thread:
Thanks everyone, I managed to sort it using JavaScript functions.
Where does that leave people viewing your site who have JavaScript turned off in their browser due to security concerns?
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

if you redirect using header(), is the POST data sent along also?

I had this problem once before. I think I solved it like this:

Code: Select all

<form method="post" action="default.html">
<input> ...
<input type="submit" value="Click for normal action">
<input type="submit" value="go somewhere else" onClick="form.action='different.html';form.submit();">
thrdnttkn
Forum Newbie
Posts: 2
Joined: Tue May 11, 2004 1:45 pm

Thank you for the _POST example

Post by thrdnttkn »

<?php
if (isset($_POST['BuyNow_x']))

I have been struggling for days with this!

Thank you!!!!!!!!!!!!!!!!!
Post Reply