I am using jQuery to submit a form when a button is clicked. I would then like to test the value of the button, however, this doesn\'t get submitted in Safari and Chrome. Wh
Give it a name.
<button type='submit' id='trash' name='trash' value="trash" class='red'>
How many values are you POSTing?
I'm not sure it sounds like your problem was solved. One thing that has not been mentioned is that you may have overshot your php max_input_vars limit.
Php is silent when you overshoot this limit, so you'll have to check the warning log, or check it this way:
1.
Count the POST array values. Scripting in var_dump($_POST);
(in a safe production sandbox environment) will do this best, as you can look at the final value output to see where the POST array "cuts off".
2.
Next, run a script to output the php information using the function: phpinfo()
. Check the value of "max_input_vars".
3. If the POST array count == the "max_input_vars" value, then you have overshot the limit.
In your case, it may be the case that the submit input would have been included later in the POST.
To edit the value (to 5000 in this example) in php.ini, add or edit this line: max_input_vars = 5000
Try like this to send a button as submit by catching a hidden input.
PHP:
<?php
if(isset($_POST['btname']))
echo $_POST['btname'];
}
?>
and html:
<form method="POST" action="" id="formname" name="formname">
<input name="btname" id="btname" type="hidden" />
<button onclick="document.formname.submit()" value="Submit">Send</button>
</form>
I think you've discovered a webkit bug.
I get the same thing testing in Chrome, your form:
<form action="" method="post">
<button id="btn" class="page-btn" type="submit" name="testBtn" value="Yes Button value is posted!">POST IT!</button>
</form>
This sends no data. If' however I add another element, an input in particular:
<form action="" method="post">
<input type="hidden" name="shim" value="" />
<button id="testBtn" class="page-btn" type="submit" name="testBtn" value="Yes Button value is posted!">POST IT!</button>
</form>
This sends both values. This is without the JavaScript. Once you add the shim hidden form element, it looks like it gets sense.
This solution needs more testing, but it may address your need.