Ok, for anyone that was following this thread or wants to know how to create a custom table and form to create records, return records, and edit records here is the code for it on the most basic level. It was started by BobRays tutorial on Custom Tables you can find here and debugged with the help of this forums members like BobRay and goldsky. Thank you.
First you need to go to BobRays tutorial
http://bobsguides.com/custom-db-tables.html to setup xPDO schemas and classes
then use this code(note: pay attention where the resources, snippets, and chunks start and end as they belong in separate files).
//Modifications need to be done to the "ShowQuotes" snippet from the tutorial
<?php
//begin snippet
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
$quotes = $modx->getCollection('Quotation');
$output .= '<p>Total: ' . count($quotes) . '</p>';
foreach ($quotes as $quote) {
$output .= $modx->getChunk('quoteTpl', $quote->toArray());
}
return $output;
// end snippet
// ?>
//The "ShowQuotes" resource
<html>
//begin resource
[[ShowQuotes]]
//end resource
</html>
//The "quoteTpl" chunk references above
<html>
//begin chunk
Author: [[+author]]<br />
Quote: [[+quote]]<br />
Topic: [[+topic]]<br />
<a href="[[~41? &scheme=`full` "eId=`[[+id]]` ]]">Edit</a><br />
//end chunk
</html>
//The "FormEdit" resource(has resource id of 41)
<html>
//begin resource
[[!EditQuote]]
//end resource
</html>
//The "EditQuote" snippet
<?php
//begin snippet
$scriptProperties['quoteId'] = !empty($_GET['quoteId']) ? intval($_GET['quoteId']) : '';
if (empty($scriptProperties['quoteId'])) {
// or you want to echo out any text
return '';
}
/* Get the existing Quote */
$path = MODX_CORE_PATH . 'components/quotes/';
$modx->addPackage('quotes', $path . 'model/', 'bobs_');
$quote = $modx->getObject('Quotation', array('id' => $scriptProperties['quoteId']));
if (isset($_POST['submit']) && $_POST['submit'] == 'submit') {
/**
* Try to see whether the field's values are empty or not, using:
* die(print_r($_POST));
*/
/* Form has been submitted */
// @todo sanitize the input values, this is IMPORTANT!
$quote->set('topic', $_POST['topic']);
$quote->set('quote', $_POST['quote']);
$quote->set('author', $_POST['author']);
if ($quote->save()) {
$output = "<p>Quote Created</p>";
$output .= '<a href="[[~22? &scheme=`full`]]">back</a>';
} else {
$output = "<p>Error when trying to save</p>";
$output .= '<a href="[[~22? &scheme=`full`]]">back</a>';
}
} else {
/* Not a repost, just display the form */
/* The second argument to getChunk() tells MODx to replace
* the placeholders with the existing quote's values
*/
$output = $modx->getChunk('quotationTplEdit', $quote->toArray());
}
return $output;
//end snippet
?>
//Now is to create a brand new record
// The "CreateQuote" snippet
<?php
//begin snippet
if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
/* Form has been submitted */
/* You might want to check for empty required fields here */
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
$fields = array(
'topic' => $_POST['topic'],
'quote' => $_POST['quote'],
'author' => $_POST['author'],
);
$quote = $modx->newObject('Quotation', $fields);
if ($quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
} else {
/* Not a repost, just display the form */
$output = $modx->getChunk('quotationTpl');
}
return $output;
//end snippet
?>
//The "quotationTpl" chunk
<html>
//begin chunk
<form method="post" action="[[~[[*id]]]]">
<input type="hidden" name="quoteId" value="[[+id]]" />
<input type="text" name='topic' id='topic' value="[[+topic]]" />
<input type="text" name='quote' id='quote' value="[[+quote]]" />
<input type="text" name='author' id='author' value="[[+author]]" />
<input type='submit' name='submit' id='submit' value='submit'/>
</form>
//end chunk
</html>
//The "Form" resource
<html>
//begin resource
[[!CreateQuote]]
//end resource
</html>