[Solved] Need help with POSTing problem

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

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

[Solved] Need help with POSTing problem

Post by mjseaden »

Dear All

The following is a basic summary of code I am currently using in a data form. The links (preview.php, clear.php, submit.php, upload.php) are image buttons pointing to those prospective URLs. Each of these pages (preview.php, clear.php, submit.php, upload.php) needs to receive the contents of the INPUT objects within the FORM below in order to carry out processing.

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>
Normally this information is posted to an URL via a SUBMIT button, whereupon the browser is redirected to the single URL given in the ACTION parameter for the form.

However, with only 1 URL able to be given for the form's ACTION parameter (I have left this as ?????.php as I don't know what to put), and with the INPUT objects containing text too large to simply be transferred through the URL via the usual e.g. url.php?text=hello&text2=goodbye, how do I post the information to <I>multiple</I> different URLs, depending on what button the user clicks on?

If it is not possible this way, is it possible any other way?

Many thanks

Mark
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

One form can only submit to one page. Change your code so that that one page does everything you need.
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

ie:

Code: Select all

&lt;form action="page.php?text=$text&amp;username=$username method=POST&gt;

Code: Select all

<?php
if (isset($text)) {
//do something
}

if (isset($username)) {
// do something
}
etc
?>
coreycollins
Forum Commoner
Posts: 67
Joined: Sun Feb 01, 2004 1:04 pm
Location: Michigan

Post by coreycollins »

Actually, not to come down on ya again tim but the action that you're showing is more the result of a get not a post. The difference between a get and a post is a get puts the results up in the url and a post does not. It does not matter whether you are going to a different page or the same page. With that said, the code should be:

Code: Select all

&lt;form action="page.php" method=POST&gt;
Then

Code: Select all

<?php
if (isset($_POST["text"])) {
//do something
}

if (isset($_POST["username"])) {
// do something
}
etc
?>
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

You've assumed I would be able to set a variable when the user clicks a button. That would require JavaScript wouldn't it?

I can't set text or username upon a user pressing a button, that requires realtime clientside code. I think that's the only way to do it.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Yea you would need to use javascript for this. I do it with a hidden for field that each button changes the value of before it submits. Then php checks the $_POST variable and acts accordingly
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Thanks everyone, I managed to sort it using JavaScript functions.
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 »

Which is why we don't like multiple posts. I just wasted time providing you with a solution (a simpler one than javascript, by the way) in one of your two other threads on this subject.

Try to limit yourself to one thread on one subject.
:twisted: :evil:
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Sorry Bill, please read the previous thread which I responded to.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

mjseaden: We are all volunteers here and Bill H's anger is very understandable. You've wasted his (and other people's) time for no reason.

one problem = one thread!
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I concur. :wink:
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

As do I :lol:
mjseaden
Forum Contributor
Posts: 458
Joined: Wed Mar 17, 2004 5:49 am

Post by mjseaden »

Okay, okay, one of them was posted around 2am in the morning my time because I am trying to make the most of whatever time I have at the moment. Someone trailed down the list and posted a reply to that thread soon before/after I posted the other one - something that could happen to anyone.

Not that that's an excuse, but lay off a bit - I really don't usually try and muck up forums with multiple threads, and I do appreciate that everyone is a volunteer here.

Mark
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Easiest solution if you haven't received a reply to a post you've made: post your own reply consisting of a simple:

"'/bump"

Simple.
Locked