Jump to content

Help me and my multiple buttons in one form problem


ternto333

Recommended Posts

I have multiple buttons in one form. One of the actions is to another PHP page which generates a CSV file, and uses headers to let the user download that file. The problem I'm having is that after pressing this button, if the user then wants to press another button, it performs the previous button's action. My javascript looks like this:

if(document.pressed == 'peptide_csv')
  {
    document.summary_form.action ="peptide_view_csv.php";
  }
  else
  if(document.pressed == 'reset_peptide')
  {
    document.summary_form.action ="peptide_view.php";
  }

In this case, if the user presses the peptide_csv button, it redirects him to peptide_view_csv.php. The code for this peptide_view_csv.php page is simple,it generates a CSV file using a header.

header('Content-type: text/plain\n');
  header('Content-Disposition: attachment; filename="peptide.csv"');
  printf("everything i print out");

The problem is that after the user presses this button, but then wants to do something else on peptide_view.php, it automatically loads up the csv and displays that for the user to download. I'm pretty sure this is happening because the header information hasn't changed since the time he first pressed the peptide_csv button, but I don't know how to change this. When the user hits refresh on the page, it doesn't do this anymore, but is there a way to build it right into the page so that you can automatically perform other actions after you've pressed the peptide_csv button?

Link to comment
Share on other sites

if you have a few buttons in the form you could try this i use it and it works for me

<script type="text/javascript">
function changeAction(ins)
{var form1 = document.getElementById('buttons');
if(ins==0)
form1.action = "thisfile.php";
if(ins==1)
form1.action = "somefile.php";
if(ins==2)
form1.action = "nicefile.php";
form1.submit();
}
</script>

to add more buttons to the .js  just copy and paste the code and change the

if(ins==#) accordingly

 

and the button is like so

 

<input type="submit" name="Submit1" onclick="changeAction(0)" value="Submit" />
<a href="#" onclick="changeAction(1)" target="_blank">Clicky Clicky</a>
<input type="submit" name="Submit3" onclick="changeAction(2)" value="Submit" />
<input type="submit" name="Submit4" onclick="changeAction(3)" value="Submit" />

 

 

 

 

Link to comment
Share on other sites

i have it set up like this, only imagine that one of your actions, "thisfile.php" goes to a page which allows a user to download a csv file. it works perfectly, but after it is done the header information is seemingly unchanged and in order to change buttons, you need to press the F5 key to refresh all the variables.

if you have a few buttons in the form you could try this i use it and it works for me

<script type="text/javascript">
function changeAction(ins)
{var form1 = document.getElementById('buttons');
if(ins==0)
form1.action = "thisfile.php";
if(ins==1)
form1.action = "somefile.php";
if(ins==2)
form1.action = "nicefile.php";
form1.submit();
}
</script>

to add more buttons to the .js  just copy and paste the code and change the

if(ins==#) accordingly

 

and the button is like so

 

<input type="submit" name="Submit1" onclick="changeAction(0)" value="Submit" />
<a href="#" onclick="changeAction(1)" target="_blank">Clicky Clicky</a>
<input type="submit" name="Submit3" onclick="changeAction(2)" value="Submit" />
<input type="submit" name="Submit4" onclick="changeAction(3)" value="Submit" />

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.