<?php
/* EditQuote Snippet */
// You might want to use this instead
$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/';
$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('quotationTplEdit', $quote->toArray());
}
return $output;
<form method="post" action="[[~[[*id]]]]">
<input type="hidden" name="quoteId" value="[[+id]]" />
<p>Author: <input type="text" name='author' id='author' value="[[+author]]" /></p>
<p>Author: <input type="text" name='topic' id='topic' value="[[+topic]]" /></p>
<p>Author: <input type="text" name='quote' id='quote' value="[[+quote]]" /></p>
<input type='submit' name='submit' id='submit' value='submit'/>
</form>[[ShowQuotes]]
<?php
$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());
/* "quoteTpl above gives html layout for "Edit" link */
}
return $output;Author: [[+author]]<br /> Quote: [[+quote]]<br /> Topic: [[+topic]]<br /> <a href="[[~41]] ?quoteId=[[+id]]">Edit</a><br />
[[EditQuote]]
<?php
/* EditQuote Snippet */
// You might want to use this instead
$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/';
$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('quotationTplEdit', $quote->toArray());
}
return $output;<form method="post" action="[[~[[*id]]]]">
<input type="hidden" name="quoteId" value="[[+id]]" />
<p>Author: <input type="text" name='author' id='author' value="[[+author]]" /></p>
<p>Author: <input type="text" name='topic' id='topic' value="[[+topic]]" /></p>
<p>Author: <input type="text" name='quote' id='quote' value="[[+quote]]" /></p>
<input type='submit' name='submit' id='submit' value='submit'/>
</form>If you do not have quotation.map.inc.php file, you can not continue. It’s dead here.
quotes
model
quotes
mysql
quotation.class.php
quotation.map.inc.php
quotation.class.php
schema
quotes.mysql.schema.xml
<?php
$xpdo_meta_map['Quotation']= array (
'package' => 'quotes',
'table' => 'bobs_quotation',
'fields' =>
array (
'quote' => '',
'author' => '',
'topic' => '',
),
'fieldMeta' =>
array (
'quote' =>
array (
'dbtype' => 'mediumtext',
'phptype' => 'string',
'null' => false,
),
'author' =>
array (
'dbtype' => 'varchar',
'precision' => '200',
'phptype' => 'string',
'null' => false,
'default' => '',
),
'topic' =>
array (
'dbtype' => 'varchar',
'precision' => '20',
'phptype' => 'string',
'null' => false,
'default' => '',
),
),
);
<?php
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
/**
* when the database becomes big, you may consider to add limit to the query, before you fetch the getCollection.
* @link http://rtfm.modx.com/display/XPDO10/xPDOQuery.limit
* modx extends the xPDO, so all the xPDO methods can be used directly:
*/
$criteria = $modx->newQuery('Quotation');
$quotes = $modx->getCollection('Quotation', $criteria);
$output = ''; // goldsky: before it's continuously appended below, it should be emptied first.
//$output .= '<p>Total: ' . count($quotes) . '</p>';
// use count as below
// @link http://rtfm.modx.com/display/XPDO10/xPDO.getCount
$output .= '<p>Total: ' . $modx->getCount('Quotation') . '</p>';
foreach ($quotes as $quote) {
/* quoteTpl above gives html layout for "Edit" link */
$output .= $modx->getChunk('quoteTpl', $quote->toArray());
}
return $output;Author: [[+author]]<br /> Quote: [[+quote]]<br /> Topic: [[+topic]]<br /> <a href="[[~41? &scheme=`full` "eId=`[[+id]]` ]]">Edit</a><br />
So, this one is the redirect page.
which shows a list of records for the user to select one to edit. Upon selecting a record. Triggers:
"FormEdit" resource page WHICH HAS A RESOURCE ID OF 41(refered to in above code)
[[EditQuote]]
which points to
"EqitQuote" snippet
<form method="post" action="">
<input type="hidden" name="quoteId" value="[[+id]]" />
<p>Author: <input type="text" name="author" id="author" value="[[+author]]" /></p>
<p>Author: <input type="text" name="topic" id="topic" value="[[+topic]]" /></p>
<p>Author: <input type="text" name="quote" id="quote" value="[[+quote]]" /></p>
<input type="submit" name="submit" id="submit" value="submit"/>
</form>

<?php
/* EditQuote Snippet */
/* Get the existing Quote */
$quote = $modx->(getObject('Quotation', array('id'=>$quoteId));
/**
* For anyone else reading this, $quoteId comes from the snippet's parameter: [[!EditQuote? "eId=`nombre`]]
*/
if (isset($_POST['submit'] && $_POST['submit'] == 'MySubmitVar')) {
/* Form has been submitted */
// this part is useless, and misleading
$fields = array(
'topic' => $post['topic'],
'quote' => $post['quote'],
'author' => $post['author'],
);
// these parts are missing
$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;
<?php //highlight
if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
// ...