I’m really stuck on this.
1. Created blank page with the following html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Some MODx page</title>
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript" src="jquery.chainedSelects.js"></script>
<script type="text/javascript">
// wait for the DOM to be loaded
$(function()
{
$('#country').change(function() {
$('#loading').show();
var options={
url: 'combo2.php',
dataType: 'json',
timeout: 1000,
error:
function() {
alert("Error loading document");
},
success:
function() {
},
//updateForm //post-submit callback
};
// submit the form
$('#formname').ajaxSubmit(options);
});
$('#loading').ajaxStart(function() {
$(this).show();
}).ajaxStop(function() {
$(this).fadeOut("slow");
});
});
function updateForm(data)
{
//do stuff with returned data, like populate a select menu with cities
$('#loading').fadeOut(500);
return true;
}
</script>
</head>
<style type="text/css">
#loading
{
display:none;
color:#CC3300;
border:2px solid #CC3300;
background:#FFCCCC;
font-weight:bold;
margin-bottom:1em;
}
</style>
<body>
<div id="loading">Loading...</div>
<form id="formname" name="formname" method="post" action="">
<!-- country combobox -->
<select id="country" name="country">
<option value="1">France</option>
<option value="2">Romania</option>
<option value="3">Usa</option>
<option value="4">Brazil</option>
</select>
<!-- state combobox is chained by country combobox-->
<select name="state" id="state" style="display:none"></select>
<!-- city combobox is chained by state combobox-->
<select name="city" id="city" style="display:none"></select>
</form>
</body>
</html>
2. Created "combo2.php" which sits on the document root with the following code:
<?php
//php
$parents = isset($_POST['parents'])? intval($_POST['parents']) : 0; // grab from hidden form field
$modx->runSnippet('Ditto',
array(
"parents" =>$country,
"depth" =>1,
"display" =>"all",
"save" =>"2",
"tpl" =>"@CODE [+id+][+pagetitle+]"
)
);
// php 5 only
echo json_encode($modx->getPlaceholder("ditto_resource"));
?>
However the MODX object isn’t loading and thus produces an error.
I tried putting the code in a snippet and then setting the Jquery URL to the page such as:
http://modx.localhost/a-test/ but this doesn’t return anything.
Putting the code outside of MODX on the document root means that the code doesn’t work.
====
Questions.
1. How do I get the php file to work with MODX objects? I need to do a lot of DB processing.
Thanks.