I am trying to code a error callback using php and ajax.
What I cannot get past is, I am assinging a variable to a $_POST in PHP to check for an empty value. If empty, then trigger error message.
However, jquery is passing the post to php as carton%5B0%5D:carton%5B1%5D:.
Would php see this as an empty post? What are these numbers etc after carton? carton is actually an array. thanks
+++UPDATE+++
Why is the error triggered when the statement becomes, !empty rather than empty?.
This is the code that jquery uses to create an input from a slider change event.
for(var i = 0;i < $(this).val();i++) {
$("#carton").append('<div data-role="fieldcontain"><label for="carton" class="ui-input-text">Enter box ' + (i + 1) + ' number:</label><input type="text" name="carton['+i+']" id="carton['+i+']" class="carton ui-input-text ui-body-null ui-corner-all ui-shadow-inset ui-body-c" /></div>')
}
to know whetever $_POST is empty always use var_dump function like this
And it might be posted as array, am not quite sure but i think arrays in ajax are like this:
array(2) { [0]=> string(0) “” [1]=> string(0) “” }
array(number) means the number of items in the array, {[0],[1]} means the array items IDs means you can use them like $_POST[1] and $_POST[0], => string(0) ; string is the datatype contained in this array item, (0) is the number of characters in that item.
to check whether the POST data is empty or not, you should use empty() function.
finally, use this to post the content you want via jquery, make sure you modify it with what you need
also you can add more POST fields by adding