Hi,
I’m creating my first CMP and need some help.
I’m trying to create a product import CMP for the visioncart module.
What I need to do is to read in a bunch of directory names, ask which directory the user wants to import, then import the contents of that directory.
I’ve got my CMP created and the first step is working, I have a drop down of the subdirectories displayed in my backend page.
I’m using a smarty template that contains a form element.
When I click submit, the browser refreshes back to the main modx manager homepage.
I guess this is to be expected. I’ve tried a form action of "" (empty) and also hardcoded to ’/manager/index.php?a=72’ (which is the url when I go to my CMP)
Obviously, both are posting back to ’/manager/index.php’ which is the homepage.
So, my questions are:
- Can you have multistage CMP’s posting back to itself?
- If you can, how do I enter the correct URL
- if not, how would I achieve my results?
I’ve a feeling people are going to say ’Do it with ExtJs’, but I’ve not used that and any pointers would be greatly appreciated.
For reference, here’s my controller code
<?php
$modx->setLogLevel(modx::LOG_LEVEL_DEBUG);
$modx->log(modX::LOG_LEVEL_DEBUG,'In importProducts module');
$baseUploadPath = $modx->getOption('proshotUploadBasePath');
$modx->log(modX::LOG_LEVEL_DEBUG,'baseUploadPath = ['.$baseUploadPath.']');
// Are we importing, or displaying a list of folders?
if (isset($_REQUEST['folder'])) {
// import folder contents
$productsToImport = getDirectoryList($baseUploadPath . "/" . $_REQUEST['folder']);
$modx->log(modX::LOG_LEVEL_DEBUG,'productsToImport = ['.print_r($productsToImport, true).']');
} else {
$productsToImport = getDirectoryList($baseUploadPath);
$modx->log(modX::LOG_LEVEL_DEBUG,'productToImport = ['.print_r($productsToImport, true).']');
$modx->smarty->assign( 'url', '/manager/index.php?a=72');
$modx->smarty->assign( 'folders', $productsToImport );
return $modx->smarty->fetch( 'selectImport.tpl' );
}
function getDirectoryList($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != "..") {
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
return 'Error, should have returned by now.';
?>
and my ’selectImport.tpl’ smarty template:
<p>Please select a folder to import:</p>
<form action="{$url}" method="GET">
<select name="folder">
{html_options values=$folders output=$folders}
</select>
<input type="submit" name="importProducts" value="Import" />
</form>
Thanks
Robin