<?php
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_');
if (! $result) {
return 'failed to add package';
}
$quote = $modx->newObject('Quotation');
$quote->set('topic', $_POST['topic']);
$quote->set('quote', $_POST['quote']);
$quote->set('author', $_POST['author']);
$quote->save();
return 'saved';
}
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_');
if (! $result) {
return 'failed to add package';
} else {
$fields = array(
'quote' => $_POST['quote'],
'topic' => $_POST['topic'],
'author' => $_POST['author'],
);
$quote = $modx->newObject('Quotation', $fields);
$quote->save();
}}
return $output;
<form method="post" action="[[CreateQuote]]">
<form method="post" action="[[~[[*id]]]]">
I have this(below) working but it is one post behind in the database. Example: fill in the three fields with 1,1,1 and hit submit. Nothing happens. Refresh the form and this time fill in the three fields with 2,2,2. When I go to the database table to see what was posted, only the 1,1,1 is now entered. The 2,2,2 wont be posted until I submit the form again. Any ideas?
<form method="post" action="[[~[[*id]]]]">
<?php
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_');
if (! $result) {
return 'failed to add package';
} else {
$fields = array(
'quote' => $_POST['quote'],
'topic' => $_POST['topic'],
'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;
if ( $quote->save()) {
$output = "Quote Created";
} else {
$output = "Error";
}
else {
/* Not a repost, just display the form */
$output = $modx->getChunk('quotationTpl');
}
return $output;