Welcome Guest, Not a member yet? Register   Sign In
Internal Server Error - 500 on post when CSRF disabled
#11

[eluser]joshmmo[/eluser]
So this is the error when I open it in a tab:

Code:
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: controllers/survey.php

Line Number: 120

Thats this line:
Code:
foreach ($order as $question_number => $question_id) {

Why would the foreach fail only when I make that call to my model?
#12

[eluser]jonez[/eluser]
[quote author="joshmmo" date="1386889099"]So this is the error when I open it in a tab:

Code:
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: controllers/survey.php

Line Number: 120

Thats this line:
Code:
foreach ($order as $question_number => $question_id) {

Why would the foreach fail only when I make that call to my model?[/quote]
$order isn't an array, data isn't being posted properly. Add the boom statement I added above but change to die(var_dump($order));

In your JS function console.log your serialize call, there's a chance it's not returning data the way you think it is.
#13

[eluser]joshmmo[/eluser]
I would have never guessed that. Thanks for pointing that out.

It now throws:

boolean false

on die.

This is what console.log shows for order:

recordsArray[]=2&recordsArray;[]=6&recordsArray;[]=1&recordsArray;[]=8&action=updateRecordsListings

How would I go about getting this data into a php array on post? Ignore the ;. These forums keep adding them in for some reason when I save my reply

Here is a SS of it instead:

http://i44.tinypic.com/jq0vh1.png
#14

[eluser]jonez[/eluser]
Click the little + beside the AJAX call showing the 500 and check out the Params tab. Does it show your post data the same as your console.log? jQuery attempts to auto detect your data's type (it could be JSON, a string, etc) and may be processing it.

Write your AJAX call like this and see what happens;
Code:
$.ajax({
url: '/survey/order/' + survey_id,
type: 'post',
data: order,
processData: false,
success: function( theResponse ) {
  $( '#status' ).html( theResponse );
}
});
#15

[eluser]CroNiX[/eluser]
You should probably also post the raw HTML (output) of what your drag and drop section looks like.

If your controller is receiving boolean FALSE, it means that it wasn't actually sent and that POST variable did not exist. Jonez is on the right track. It seems to be a problem in the JS or HTML resulting in inconsistent data being sent to the controller.
#16

[eluser]joshmmo[/eluser]
This is the tab:

http://i44.tinypic.com/20gefev.png

However I am still getting boolean false on
Code:
if (!is_array($order))die(var_dump($order));

Thanks for helping me sort through this jonez. Is there a way to tell for sure what data type jquery is trying to send it as?


This is what my html looks like for the drag/drop

Code:
<div id="status"></div>

<ul id="order" class="list-group">
   <li class="list-group-item" id="recordsArray_1">How easy was it to find the answer you were looking for?</li>
   <li class="list-group-item" id="recordsArray_2">How easy was it to follow the steps in the help resource?</li>
   <li class="list-group-item" id="recordsArray_6">If you could change one thing about our help resources what would it be?</li>
   <li class="list-group-item" id="recordsArray_8">Is Josh Awesome?</li>
</ul>
#17

[eluser]jonez[/eluser]
[quote author="CroNiX" date="1386955679"]You should probably also post the raw HTML (output) of what your drag and drop section looks like.

If your controller is receiving boolean FALSE, it means that it wasn't actually sent and that POST variable did not exist. Jonez is on the right track. It seems to be a problem in the JS or HTML resulting in inconsistent data being sent to the controller.[/quote]
You can also die(var_dump($this->input->post())); in CI to see everything the client sent to the server.

Change your markup to this;
Code:
<ul id="order" class="list-group">
   <li class="list-group-item" data-id="1">How easy was it to find the answer you were looking for?</li>
   <li class="list-group-item" data-id="2">How easy was it to follow the steps in the help resource?</li>
   <li class="list-group-item" data-id="6">If you could change one thing about our help resources what would it be?</li>
   <li class="list-group-item" data-id="8">Is Josh Awesome?</li>
</ul>

Then change your JS function to this;
Code:
var order = $( '#order' ).children( ),
data = [ ],
i, len;

for ( i = 0, len = order.length; i < len; i++ ) {
data.push( order[ i ].getAttribute( 'data-id' ) );
}

console.log( data ); //should be an array of ids

$.ajax({
url: '/survey/order/' + survey_id,
type: 'post',
data: { recordsArray: data },
success: function( theResponse ) {
  $( '#status' ).html( theResponse );
}
});
It may seem tedious but I usually write my own serialize calls. It gives you more control on how you post the data (you can set the post key and send less/more if you want to).
#18

[eluser]joshmmo[/eluser]
Thanks for the help! It seems I am getting posts just fine now, I see a new error message but I know what the issue is now. Thank you guys for your time.
#19

[eluser]jonez[/eluser]
No problem!




Theme © iAndrew 2016 - Forum software by © MyBB