<?php
/* CreateQuote Snippet */
if (isset($_POST['submit']) && $_POST['submit'] == 'send') {
/* Form has been submitted */
/* You might want to check for empty required fields here */
$fields = array(
'topic' => $_POST['topic'],
'quote' => $_POST['quote'],
'author' => $_POST['author'],
);
$quote = $modx->newObject('Quotation', $fields);
$output = print_r($fields);
if ( $quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
} else {
/* Not a repost, just display the form */
/*$output = "POST-Content:" . print_r($_POST); #always empty
$output .= $modx->getChunk('quotationTpl'); */
$output = $modx->getChunk('quotationTpl');
}
return $output;
<form action="[[~[[*id]]]]" method="post" class="form">
<label for="topic">
Topic:
</label>
<input type="text" name="topic" id="topic" />
<label for="quote">
Quote:
</label>
<input type="text" name="quote" id="quote" />
<label for="author">
Author:
</label>
<input type="text" name="author" id="author" />
<input type="submit" value="send" name="submit" />
</form>
This question has been answered by Bruno17. See the first response.
$result = $modx->addPackage('quotes',$path . 'model/','bobs_');
if (! $result) {
return 'failed to add package';
} [[!CreateQuote]]

/* CreateQuote Snippet */
/* Path and check if package can be added */
$path = MODX_CORE_PATH . 'components/quotes/';
$result = $modx->addPackage('quotes',$path . 'model/','bobs_');
if (! $result) {
return 'failed to add package';
}
/* Checking if form has been submitted */
if (isset($_POST['submit']) && $_POST['submit'] == 'send') {
/* Form has been submitted */
/* You might want to check for empty required fields here */
$fields = array(
'topic' => $_POST['topic'],
'quote' => $_POST['quote'],
'author' => $_POST['author'],
);
$quote = $modx->newObject('Quotation', $fields);
#$output = print_r($fields);
if ( $quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
} else {
/* Not a repost, just display the form */
$output = $modx->getChunk('quotationTpl');
}
return $output;
