What I mean is the top portion of the code works for posting data to database but following the resto of the tutorial here:
http://bobsguides.com/custom-db-tables.html
is giving errors. This is the portion I cant seem to figure out.
if ( $quote->save()) { $output = "Quote Created"; } else { $output = "Error"; } else { /* Not a repost, just display the form */ $output = $modx->getChunk('quotationTpl'); } return $output;
/* EditQuote Snippet */
/* Get the existing Quote */
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
$quote = $modx->getObject('Quotation', array('id' => $quoteId));
if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
/* Form has been submitted */
$fields = array(
'topic' => $_POST['topic'],
'quote' => $_POST['quote'],
'author' =>$_POST['author'],
);
if ($quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
} 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('quotationTpl', $quote->toArray());
}
return $output;<?php
/* ShowQuotes snippet */
$quotes = $modx->getCollection('Quotation');
foreach($quotes as $quote) {
$output .= $modx->getChunk('quoteTpl', $quote->toArray());
}Author: [[+author]]<br /> Quote: [[+quote]]<br /> Topic: [[+topic]]<br /> <a href="[[~##]]?quoteId=[[+id]]">Edit</a><br />
<?php
/* EditQuote Snippet */
/* Get the existing Quote */
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
$quote = $modx->getObject('Quotation', array('id'=>$_GET['quoteId']));
if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
/* Form has been submitted */
$fields = array(
'topic' => $_POST['topic'],
'quote' => $_POST['quote'],
'author' => $_POST['author'],
);
if ( $quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
} 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('quotationTpl', $quote->toArray());
}
return $output;
<form method="post" action="[[~[[*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>
[[EditQuote? quoteId=`[[+id]]`]]
<?php
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
if (!$result) {
return 'failed to add package';
} else {
$output = '<p>added Package</p>';
}
$quotes = $modx->getCollection('Quotation');
$output .= '<p>Total: ' . count($quotes) . '</p>';
foreach ($quotes as $quote) {
$output .= $modx->getChunk('quoteTpl', $quote->toArray());
}
return $output;Author: [[+author]]<br /> Quote: [[+quote]]<br /> Topic: [[+topic]]<br /> <a href="[[~41]]?quoteId=[[+id]]">Edit</a><br />
<input type="hidden" name="quoteId" value="[[+id]]" />
<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>[[EditQuote? quoteId=`[[+id]]`]]
$quote = $modx->getObject('Quotation', array('id'=>$_GET['quoteId']));
$quote = $modx->getObject('Quotation', array('id'=>$_REQUEST['quoteId']));
if (! $quote) {
return "Could not retrieve quotation. Request[quoteId] = " . $_REQUEST['quoteId'];
}
http://www.mywebsite.com/formedit.html?quoteId=1223
http://www.mywebsite.com/formedit.html
<?php
/* EditQuote Snippet */
// You might want to use this instead
$scriptProperties['quoteId'] = !empty((int) $_GET['quoteId']) ? (int) $_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/';
$result = $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 = "Quote Created";
} else {
$output = "Error";
}
} 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('quotationTpl', $quote->toArray());
}
return $output;
Parse error: syntax error, unexpected T_INT_CAST in C:\wamp\www\modx\core\cache\elements\modsnippet\39.include.cache.php on line 10
$quote = $modx->getObject('Quotation', array('id'=>$scriptProperties['quoteId']));