-1

I have a form using GET method. This form might have large amount of fields to update. so sometimes the URL gets too long. so I thought I can add more buttons to update each group of fields seperatedly.

The problem, even if I add a new button, it sends all FORMs parameters. How can I send only some of the parameters?


Edit: I cannot replace the GET to POST because this page is called not just from itself but also from other pages, so two of the parameters must be used as GET. I tried

if(isset($_GET['param_id1'])) {
           $param_id1 = $_GET['param_id1'];
       } else if(isset($_POST['param_id1'])){
           $param_id1 = $_POST['param_id1'];
       }

and within the form -

printf ("<form method='post' action='update_order.php'>"); // Use POST instead of GET
printf ("  <input type='hidden' name='param_id1' value='$param_id1'>");

but it also did not work.

Edit 2: It did not work because I forgot to also change the URL -

<form method='post' action='update_order_test_post.php'> 

My Form: [I Use PHP]

<form method='get' action='update_me.php'> 
 . . . 
<input type='submit' name='Submit' value='Update All'>   <!-- Original button -->
 . . . 
<input type='submit' name='Submit' value='Update One Line'> <!-- New button -->

Original URL: Seperated with newLines for clearence

http://mySite.com/update_order.php?
&infoA=aaa
&infoB=bbb
&infoC=ccc
&Submit=Update
&param1[1]=11
&param2[1]=21
&param3[1]=31
&param4[1]=41
. . . 
&param1[2]=211
&param2[2]=221
&param3[2]=231
&param4[2]=241
. . . 
&param1[3]=3311
&param2[3]=3321
&param3[3]=3331
&param4[3]=3341
. . . 
&param1[4]=411
&param2[4]=421
&param3[4]=431
&param4[4]=441
. . . 
. . . 

I want to send only the following fields to the new URL, e.g. if the button in line 3 was clicked:

http://mySite.com/update_order.php?
&infoA=aaa
&infoB=bbb
&infoC=ccc
&Submit=UpdateOneLine
&param1[3]=3311
&param2[3]=3321
&param3[3]=3331
&param4[3]=3341
. . . 

Thanks, Atara.

Atara
  • 3,523
  • 6
  • 37
  • 56
  • 5
    Updating data should be used with POST ; not GET. – Pascal MARTIN May 20 '12 at 10:19
  • Any particular reason why you're not using POST? – JJJ May 20 '12 at 10:20
  • suppose I replace the GET to POST, how do I send only some of the parameters? – Atara May 20 '12 at 10:26
  • 1
    *(related)* [When do you use POST and when do you use GET](http://stackoverflow.com/questions/46585/when-do-you-use-post-and-when-do-you-use-get) – Gordon May 20 '12 at 10:27
  • 1
    @Atara if you dont intercept and prune the data to be submitted with JavaScript you have to use multiple forms. That's the only way to make this work from HTML alone. You might want to consider that anyway, since very long forms are not userfriendly. – Gordon May 20 '12 at 10:28
  • 1
    If you use POST you don't need to split the parameters anymore. – JJJ May 20 '12 at 10:29
  • I ended up using POST. Thank you all! – Atara May 20 '12 at 11:40

2 Answers2

2

Use POST, that's what its for.

If you use POST then you don't need to worry about reducing the number of items submitted. It may seem like it is a large number of items, but in terms of data you're probably only dealing with a maximum of 10K of data being sent. The rest of your page is likely somewhere between 50 - 300K so its only a small part.

Just Change the form method to POST and use the parameters you need in your php receiving page.

UPDATE To answer your specific question though, if you make each row a seperate form then it will only submit that row when the user clicks the submit button

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
1

@Atara usage of POST will definitely solve your problem. As you can't hit a POST action in the address bar of your browser.

SKL
  • 77
  • 6