Page 1 of 1

Multiple buttons posting to pages without multiple forms.

Posted: Sun Nov 16, 2003 12:45 pm
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.

Posted: Sun Nov 16, 2003 1:00 pm
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.

Posted: Sun Nov 16, 2003 3:58 pm
by DustParticle
Thanks man will try it out! :)