0

I am working on a system that allows the user to preview the result as an HTML table. I put a checkbox in the leftmost cell that is checked by default. Should the user uncheck any row, that row will not appear in the final product.

Submitting this form, which as of now is only these checkboxes, with just HTML yields a 404 error. Removing or significantly reducing the number of the checkboxes fixes this problem.

I implemented name = "checkbox[]" instead of name = "checkbox1", name = "checkbox2", ... to see if that would solve the problem; it didn't.

I also tried serializing and submitting the form data with jQuery post and PHP, which still gives me the 404. I tried submitting the form using AJAX and jQuery to the same effect.

I'm not sure if submitting the data through $_SESSION will help. I don't know how I would implement this in my use case.

How can I submit many inputs without causing an error?

EDIT: A hopefully minimal, complete and verifiable example (using only HTML, since none of the scripting methods produced a better result):

<?
print "<form action = 'target.php' method='get'>";
for( $i = 0 ; $i < 200 ; $i++ ){
   print '<input type="checkbox" name="chk[]" checked /> Checkbox ' . $i . '<br />';
}
print '<input type="submit" value="Submit">';
?>

This produces the same error for me: 404.

Aditya J.
  • 131
  • 2
  • 11
  • Which HTTP method are you using to send that payload to backend? And which request method is expecting your backend? – Ele Jul 25 '18 at 21:32
  • I have tried GET and POST – Aditya J. Jul 25 '18 at 21:34
  • Which endpoint is posted to for the both the 200 and 404 requests? – Clint Jul 25 '18 at 21:34
  • A 404 error indicates that the page you are submitting the data to doesn't exist. This will get triggered **before** any potential errors with your data itself. You're simply sending your data to the wrong page. Please add a [**minimal, complete, and verifiable example**](http://stackoverflow.com/help/mcve) of your submission. – Obsidian Age Jul 25 '18 at 21:36
  • The client and backend should work with the same HTTP method, further, that amount of data must be sent using the HTTP POST method. Please post a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Ele Jul 25 '18 at 21:36
  • A 404 error means the page is not found. I therefore don't see an inmediate relation with your form submission. The problem here is that we cannot reproduce your problem. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – KIKO Software Jul 25 '18 at 21:36
  • @Clint, clicking on the address bar shows that the form was submitted to the correct file. I'm afraid I haven't been doing this long enough to understand your question if that isn't what you're asking – Aditya J. Jul 25 '18 at 21:37
  • Which HTTP method is expecting your endpoint? – Ele Jul 25 '18 at 21:38
  • A 404 is "not found", but if this is a **404.13** then you may be exceeding a configured request size limit. Can you provide *specifics* about the error, such as server logs or something of that nature? – David Jul 25 '18 at 21:40
  • @David exceeding the configured request size limits sounds exactly right. I have little to no access on the machine this is running on, but is the request size limit something I can get from `phpinfo();`? – Aditya J. Jul 25 '18 at 21:48
  • If the endpoint is expecting `PATCH` method and you're sending `POST` or `GET` that will result on a `404` error. – Ele Jul 25 '18 at 21:54
  • @Ele I wrote the endpoint as well, and I don't think it is expecting `PATCH`. – Aditya J. Jul 25 '18 at 21:58

1 Answers1

3

Replace <form action = 'target.php' method='get'> with <form action = 'target.php' method='post'>

You use the GET method, which means that the input names and values will be sent in the URL. If you send data to the server, always use POST.

If you have 100+ inputs, then the URL gets too long

Iter Ator
  • 8,226
  • 20
  • 73
  • 164