I have a form with 1222 fields (I know the number is large, but it's a form for saving translations). When I submit the form, the script is not executing. I get no error message and the error log is empty. Even if the script I post to contains only an echo command, nothing is executed and all I see is a blank page.
I am quite sure this is a PHP setting problem, as the form can be submitted without any problems on other servers. Can anyone shed some light on what the issue could be?
The HTML is:
<form action="test.php" method="post">
<input type="text" name="account-form-282f96c7d1ed98d24606d209dcad9842" value=""/>
<!-- 1221 more inputs with different names, but format is the same as above -->
<input type="submit" name="submitBT" value="Save"/>
</form>
test.php:
<?php
echo(1);
?>
Edit 1:
If I simplify the input names, e.g.: input_1, input_2 etc. the submit works fine.
Edit 2:
I noticed I receive a 406 Not Acceptable HTTP response.
The problem is with mod_security, for some reason it didn't like the submitted data and stopped the execution of the script.
Related
I have a script that pulls an XML page and uses a form to update and save the values back. When I click the submit button it works, but then the page loads blank. I just want the page to refresh. There are about 100 different threads on this, and nothing I have tried has worked to resolve the issue. Out of curiosity, I just tried to run the window.location script and nothing else, and this piece actually doesn't work at all.
<?php
//if (isset($_POST['submit'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//$ctstatus->nodeValue = $_POST['ctstatusform'];
//htmlentities($xml->save('test.xml'));
echo '<script type="text/javascript">window.location="http://google.ca";</script>';
}
?>
The inner contents of the form don't really matter at this point, I just want it to refresh the page after I hit the submit button.
I previously used isset but from reading it seems like that's obsolete, and my form action="" used to be blank. Either way my XML save works, but nothing to refresh the page. I also tried header and that didn't work either.
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<input class="save" name="submit" type="submit" value="Save" />
</form>
Out of curiosity I tried an onClick function with a timer and this does work but it's not ideal at all, especially because the page could technically refresh before the POST is finished writing the file. I'd rather know why the echo doesn't execute.
PHP redirect would most likely be preferable to JavaScript redirect.
Typical structure when posting back to same page:
<?php // cannot be any output before this (space, linefeed, etc)
if(isset($_POST['submit']) {
// do stuff with the submission
header('Location: http://google.ca');
exit;
}
// does your script need to do some other data retrieval or calculation? do it here.
?>
<html>
... snip ...
<form method="post">
... snip ...
<input class="save" name="submit" type="submit" value="Save" />
</form>
Following this simple structure for procedural scripts--
Deal with user input / redirect
Do logic (collect, manipulate data)
Show output (using php only to insert variables and looping)
will help you avoid a lot of heartache and technical debt.
Okay, I have gotten this sorted out. It turns out that the problem was embarrassingly simple, but maybe will assist someone in the future. Along with reordering my code, as Tim suggested. I specified HTML as the DOCTYPE, and that worked to resolve the issue. I no longer need to worry about refreshing the page after submit, because it refreshes as it should automatically. Thank you to everyone who commented.
406 Not Acceptable error occurs in form when textarea contains raw html (input type checkbox)
Hi guys/gals, very strange problem I'm having. Let me gt right into it:
I tested my site on Windows 7, Xampp 3.0.12 and using localhost everything works as it should...however, after uploading my site to godaddy cPanel, the 406 error began to occur, mentioned this in case it is relevant.
Problem:
I have a series of forms, 1 form to upload picture & text, 2nd form to use data from form 1 to fill in form 2 to get appropriate values (these two forms are on page1.php, upon submission of 2nd form that contains textarea fields that are holding html code to be sent to a new .php page (page2.php) the error displays.
After testing further to find the source of the error I find that the forms work properly if input type="" is not included in the textareas upon submission. If these input fields are included the error is thrown.
I have provided the code below that I think is relevant to solving this problem, but if there is something missing, let me know and I will add whatever is needed so we can get to a solution.
Form 1 looks like:
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post" enctype="multipart/form-data">
//contains input type text, file fields
<input name="submit" type="submit" value="">
</form>
Form 2 looks like:
<FORM NAME="product-submit-form" ACTION="http://www.mywebsite.com/product-live-demo.php" METHOD="POST" enctype="multipart/form-data">
//contains input type text, number, and includes textarea fields
//like this one below.
<div class="textarea-size">
<ul class="result2" contenteditable="true"></ul>
<textarea id="sizes" name="sizes" rows="8" cols="30" title="content">
</textarea>
</div>
<input type="submit" value="" name="submit-demo">
</form>
This is a sample of the code that is being inputed into the textarea fields:
<div class="checkbox-black"><input type="checkbox" id="black" name="Color:_Black" value="Yes"><label for="black" title="Black"></label></div>
The code above throws the 406 error, whereas if I simply delete <input type="checkbox" id="black" name="Color:_Black value="Yes"> then the error does not show.
This strikes me as odd because I have run a javascript that transforms the html code into raw text so it can be submitted in its raw text form properly to be rendered as html code in the next page. So, i just can't see why this particular piece of text is causing an error.
The javascript I have on page1.php with form 1 & 2 is here:
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
var el = $(this).closest('.box-checkbox-size').find('.rawHTML-code-insert2');
var title = el.html();
var id = el.data('id');
// If the checkbox is checked, add the item to the ul.
if($(this).is(':checked')){
var html = $("<li/>", {
title: title,
text: title,
id: id
});
$('ul.result2').append(html);
} else {
// if the checkbox is unchecked, remove the item from the ul.
$('li#' + id).remove();
}
});
});
</script>
On page2.php the form (form 3-demo) looks like this:
<form action="https://mysite.foxycart.com/cart" method="post">
// the foxy cart action value I added but the demo is not meant to be a
// working version, only a visual representation of what it would look like
<div class="box-checkbox-size">
<?php echo $_POST['sizes'] ?>
</div>
//other content
<input type="submit" value="" class="submit">
</form>
Attempted Solutions:
1.) I tried altering the accept charset="" values from utf-8 to ISO-8859-1 and vice versa on the forms but i gave up after trying about 6 different combinations with the forms I have. If this is the root of the error please let me know what values go for which form. thx
2) I also tried adding enctype="multipart/form-data" to form 3 but that seemed to have no effect.
3) I researched a little on godaddy and said .htaccess may be a cause but no detailed instructions were provided on how to remedy this type of problem.
This is all I have at the moment, if anyone can offer a solution it would be most helpful.
Thankyou
I encountered the same error on godaddy
basically change the name of input fields to body1..2..3
http://w2cschool.com/How/How-To-Manage-Not-Acceptable-406-error-On-Godday-Server-/1170
In regards to a site on your hosting account, the cause of the 406 error is usually due to a mod_security rule on the server. Mod_security is a security module in the Apache web server that is enabled by default on all hosting accounts. If a site, page, or function violates one of these rules, server may send the 406 Not Acceptable error.
You said that it worked fine on your localhost, that means you need to talk to godaddy, and see if they could disable specific ModSecurity rules.
Try this article: http://www.inmotionhosting.com/support/website/modsecurity/find-and-disable-specific-modsecurity-rules
use name="description" or name="message" in your name attribute ..
Hope This is solved your problem
Example
<textarea name="message" rows="8" cols="30" >
After alot of digging around some very informative posts and info to try and find out how to solve this issue I thought I would ask around to see if anyone has any pointers.
I have an html form with various inputs (checkboxes, text boxes etc...). Each input section has its own submit or 'Upload' button. On Upload a php script is called and various bits of processing is done before data is sent over a pipe to a Python script for further stuff.
I am currently echoing back input variables to the form on submission so that the html page does not refresh (or should I say the inputted data is not lost to the users view) on an Upload event, however, I now have to do the same for a bunch of checkboxes and text boxes the values of which are stored in an array. The code I have written so far is as follows (I am new to both php and html so please excuse the inefficiency that I'm sure is obvious)
html/php
<margin>CH1</margin><input type="checkbox"name="ANout[]"value="AN1_OUT"
<?php if(in_array('AN1_OUT',$_POST['ANout']))echo'checked';?>>
Voltage<input type="text"size="5"name="ANout[]"
value="<?php $ANout[$i]=$_POST['ANout'];
if(!empty($ANout[$i]))echo"$ANout[$i]";?>">
<br>
The code above works fine for the checkboxes which happily remain after an Upload button is pressed but not for the array. When the Upload event occurs I simply get 'Array' written in the text box. I have tried existing code I have written to echo back other text input in the form (see below) and which works but these are for sole entries, not arrays. I have tried various configurations of syntax but I always seem to get the same result.
Working Code:
<margin>Duty Cyle</margin><input type="text"name="PWM1DC"size="3"
value="<?php $PWM1DC = $_POST['PWM1DC'];
if(!empty($PWM1DC))echo "PWM1DC";?>">
<br>
I'm sure it is something straightforward but I have been fiddling and staring at it for ages and can't seem to find the problem.
You are getting "Array", because you are trying to print out variable of type Array.
You probably want to give your fields separate names or indexes and do something like this:
<form method="post">
<input type="checkbox" name="ANout[1]" value="AN1_OUT"
<?php if(isset($_POST['ANout']) && in_array('AN1_OUT',$_POST['ANout']))echo'checked';?>>
Voltage<input type="text"size="5"name="ANout[2]"
value="<?php if(isset($_POST['ANout']) && !empty($_POST['ANout'][2])) echo $_POST['ANout'][2]; ?>">
<input type="submit" value="ok">
</form>
(Just added form tags, submit button and isset checks to show working example.)
I've been tinkering with this for a few days. Checked out all the posts related and still can't quite get it to work. Anyone able to take a look and steer me in the right direction?
I have a site where everything gets loaded into a div on a page.
everything is working great except the form data.
I can load the session data for a test and it works fine, however i can't seem to get any of the entered form data.
i have the session_start(); included at the top just under the opening php tag in connection.php. connection.php is required on each page.
connection.php beginning.
<?
session_start();
Here are some code samples from addvehicle.php (not posting it all as it's huge and the rest is not relevant, can if need be though)
...
<script type="text/javascript">
$(document).ready(function()
{
$('form#newvehicleform').submit(function()
{
<?php
$trucknumbera=$_POST["trucknumber"];
$_SESSION['trucknumber']=$trucknumbera;
$_SESSION['info']="this is some info";
?>
$("#mainwindow").load("addvehiclepost.php");
return false;
});
});
</script>
.....
<form id="newvehicleform" class="newvehicleform" method="post" action="<?php echo $PHP_SELF;?>">
<table>
<tr>
<td>
Truck Number
</td>
<td>
<input name="trucknumber" class="validate[required,custom[number]]" type="text" id="trucknumber" autofocus autocomplete="off" required />
</td>
</tr>
<tr>
<td>
<br>
<input type="submit" id="submit" class="s-submit" alt="Submit" value="Submit">
</td>
</tr>
</table>
</form>
the test of, addvehiclepost.php
require ('./connection.php');
echo "<br>info: " .$_SESSION['info']. "<br>";
$trucknumber=$_SESSION['trucknumber'];
echo "<br>trucknumber: " .$trucknumber;
and here is the output i get from addvehiclepost.php
info: this is some info
trucknummer:
so you can see it's passing the $_SESSION properly and that function is working however I just can't get it to pass the submitted for data.
Anyone have any ideas on getting this to go?
Thanks in advance.
-Colin.
When you execute your first script with PHP, there is no form data.
And the PHP fragment executed there does not do anything besides transfering an empty POST value (NULL) to a local variable and then to the session array.
I think you think that this PHP code gets executed when the javascript is called, but this is not the case! First all PHP is executed, and the result is echoed back to the browser. Then the page is rendered and javascript is executed.
So the PHP part of your code does copy an empty value (and sets a static one as well, that's what you see) at the time the form page is first loaded by the browser.
Then javascript acts. Which would mean in your case that there is no form POST request, but simply a GET request for the addvehiclepost.php script. No POST request means no $_POST data. Which isn't accessed in the loaded script anyway.
I don't know if you are able to fix this, but I hope I enabled you to understand the structural error of your code. I have seen this with about any newbie I know.
On our website, sometimes $_POST is relayed empty to the action pages.
This happens for roughly about %1-2 of the forms submitted on a daily basis. This is about 50-100 corrupt form submissions per day currently.
We are certain the data is there on the initial page. We tried sending the same data with $_POST and $_GET at the same time with the exact same values. $_GET reaches the action page all the time, but $_POST can arrive empty.
Often times, this error happens to Webkit besed browsers. Also mobile phone browser seem to be more prone to this.
IE browsers experience this less than the Webkit browsers.
And very rarely it happens to Firefox as well.
Current configuration is like this:
PHP Version 5.2.15
Centos 5
Apache 2.2.3
One thing we are discussing is to upgrade our PHP to 5.3.x.
Does that sound like a reasonable try?
Any suggestions on how we can try to debug this?
UPDATE:
Submission form is as follows:
<form action="submit.php?receiver_user_id=<?php echo $_SESSION['receiver_user_id'];?>&sender_user_id=<?php echo $_SESSION['user_id']; ?>" method="post">
<textarea name="message_text" ></textarea>
<input type="hidden" name="receiver_user_id" value="<?php echo $_SESSION['receiver_user_id'];?>
<input type="hidden" name="sender_user_id" value="<?php echo $_SESSION['user_id']; ?>
<input type="image" name="submit" src="submit.png" value="submit"/>
</form>
Could it be that some sort of input to the form makes the sending fail, or, assuming you judge the 1-2% by empty database entries, makes the storing fail, respectively?
[edit] That sounds stupid... What I meant was, if you have a loop submitting the form 1000 times with the same values, does 1-2% still go empty, or could it be up to what is sent, that the form goes empty?
Adding
<?php header("Connection: close"); ?>
cleared the problem on our end. Apparently this relates to keep-alive and IE. You can read more about it here:
Why does Internet Explorer not send HTTP post body on Ajax call after failure?