Quote:
Originally Posted by Rowsdower!
OK, we have a pulse. Now you can see that the AJAX response is not what you expected it to be, so we look at what we're actually sending to the ajax.php file...
Code:
var data_send = 'col='+col+'&wval='+encodeURIComponent(wval);
Suppose we just changed the select box to use Option 1. What does that give us for the $_POST string that we are generating?
col is passed as a parameter of the function call from the onchange event handler and it is known to be "1" for us.
Code:
'&wval='+encodeURIComponent(wval)
wval is also passed as a parameter of the function call, and is equal to the value of the option that has been made selected. So if we are selecting "Option 1" from the dropdown, then the value we pass to the function is "1".
So overall, our $_POST request (which you indicate uses a $_REQUEST in the PHP to get values for, meaning we can test with simple $_GET strings) is a simple "col=1&wval=1"
Testing that via $_GET, we end up tagging this URL:
http://www.kxdesign.com/test/ajax.php?col=1&wval=1
And...we get a blank page. So when the AJAX response wipes out your select box contents this is why. You haven't given any contents to replace them with. Nevermind the fact (for now) that the response is being populated in the wrong spot. Lets first find out why we are getting a blank page for a result.
Can you post your ajax.php script so I can see what you're actually testing for? Also, do you have error reporting enabled? If not, you should enable it right now so we can be sure of whether or not your PHP script is choking on an error of its own.
|
error reporting is set to error_reporting(E_ALL & ~E_NOTICE);
The part of code in ajax.php (it is a large file, mostly consists of vBulletin functions) is this:
Code:
if (isset($_POST['col']) && isset($_POST['wval']))
{
$vbulletin->input->clean_array_gpc('p', array(
'col' => TYPE_STR,
'wval' => TYPE_STR
));
$preid = 'zfield_';
$col = trim(strip_tags($_POST['col']));
$wval = "'" . trim(strip_tags($_POST['wval'])) . "'";
$optionid = $vbulletin->db->query_first("SELECT assignfield
FROM " . TABLE_PREFIX . "ziki_franco_option
WHERE optionid = '". $wval ."'");
if ($optionid['assignfield'] != '0' AND $optionid['assignfield'] != 'input')
{
$subfield = $vbulletin->db->query_first("SELECT *
FROM " . TABLE_PREFIX . "ziki_franco_field
WHERE id = '". $optionid['assignfield'] ."'");
$suboptions = $vbulletin->db->query_read("SELECT *
FROM " . TABLE_PREFIX . "ziki_franco_option
WHERE fieldid = '". $optionid['assignfield'] ."'");
while ($suboption = $vbulletin->db->fetch_array($suboptions))
{
$subfieldbits .= '<option value="' . $suboption['optionid'] . '">' . $suboption['value'] . '</option>';
}
$templater = vB_Template::create('ziki_franco_subfield');
$templater->register('subfield', $subfield);
$templater->register('subfieldbits', $subfieldbits);
$templater->render();
}
elseif ($optionid['assignfield'] == 'input')
{
$categories = fetch_socialgroup_category_options();
$categoryoptions = '';
foreach ($categories as $categoryid => $category)
{
$optiontitle = $category['title'];
$optionvalue = $categoryid;
$optionselected = ($categoryid == $group['socialgroupcategoryid'] ? ' selected="selected"' : '');
$categoryoptions .= render_option_template($optiontitle, $optionvalue, $optionselected, $optionclass);
}
unset($categories);
//not working yet
$templater = vB_Template::create('ziki_franco_inputfield');
$templater->register('categoryoptions', $categoryoptions);
$templater->register('group', $group);
$templater->render();
}
Maybe I should use $_GET instead of $_POST?
Edit: I was thinking, that I will rebuild this, to use a system or parent and subfields to make this easier. So that all select boxes will already be created but only the first one will have options, the subsequent won't, then upon the change of the parent field, they would populate the options. I think this is an easier approach than making them appear based on the option (like this
http://www.dhtmlgoodies.com/scripts/...-select.html)? It's more logical