Multiple buttons posting to pages without multiple forms.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
DustParticle
Forum Newbie
Posts: 2
Joined: Sun Nov 16, 2003 12:45 pm

Multiple buttons posting to pages without multiple forms.

Post by DustParticle »

This isn't really a PHP problem but I figure someone here might have some advice for me. Here is a basic idea of what I wanna do:

1 page
2 buttons on page
1st button must have form action for current page
2nd button must redirect to another page but POST the category id

I did try use headers but web server where site is hosted has problems with headers. Besides I want the vars to remain POST. Using the header function makes them GET.

Anyone got any ideas for me? I can elaborate if you don't understand. Please help.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

It can be done with JavaScript:
  • Create a <form action="normal_post.php" ... /> with 2 buttons, one of them is <input type="submit" ... />
  • The other button call a JavaScript function (onClick="javascript:submitForm(this.form);") that changes the <form>'s action= attribute to something else and submits it:

    Code: Select all

    function submitForm (form) &#123;
      form.action = 'other_post.php';
      form.submit();
      return;
    &#125;
Cheers,
Scorphus.
DustParticle
Forum Newbie
Posts: 2
Joined: Sun Nov 16, 2003 12:45 pm

Post by DustParticle »

Thanks man will try it out! :)
Post Reply