$modx->log(modX::LOG_LEVEL_ERROR, 'THIS HOOK IS BEING INVOKED!', '', 'chronicleThis Hook'); $prefix = 'xyz_'; $packagename = 'chronicleThis'; $classname = 'Grows'; $formFields = $hook->getValues(); if ( isset( $formFields['grow_id'] )) { $modx->log(modX::LOG_LEVEL_ERROR, 'grow_id: '.$formFields['grow_id'], '', 'chronicleThis Hook'); $where = array( 'grow_id', $formFields['grow_id'] ); unset( $formFields['grow_id'] ); } $packagepath = $modx->getOption($packagename . '.core_path', NULL, $modx->getOption('core_path') . 'components/' . $packagename . '/'); $modelpath = $packagepath . 'model/'; $modx->addPackage($packagename, $modelpath, $prefix); if ( is_array( $where )) { $dataobject = $modx->getObject($classname, $where); if (empty($dataobject)) { $dataobject = $modx->newObject($classname); } } else { $dataobject = $modx->newObject($classname); } if (!is_object($dataobject) || !($dataobject instanceof xPDOObject)) { $errorMsg = 'Failed to create object of type: ' . $classname; $hook->addError('error_message', $errorMsg); $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Hook'); //return false; } foreach ($formFields as $field => $value) { if (!in_array($field, $removeFields)) { if (in_array($field, $arrayFields)) { switch ($arrayFormat) { case 'json': $value = json_encode($value); break; case 'csv' : default : $value = implode(',', $value); break; } } $dataobject->set($field, $value); } } if (!$dataobject->save()) { $errorMsg = 'Failed to save object of type: ' . $classname; $hook->addError('error_message', $errorMsg); $modx->log(modX::LOG_LEVEL_ERROR, $errorMsg, '', 'chronicleThis Hook'); return false; } return true;
[[!FormIt? &hooks=`chronicleThis` ]] <form name="form" id="form" action="[[~[[*id]]]]" method="post" class="form"> <input type="hidden" name="owner_id" id="owner_id" value="[[!+modx.user.id]]"> [[!+grow.id.field]] <li class="fieldOuterBox"> <label for="title" class="inputLabel">Title</label> <input type="text" name="title" id="title" class="txtInput" value="[[!+grow.title]]" /> <span class="applyError">[[!+fi.error.title]]</span> </li> <li class="fieldOuterBox"> <label for="description" class="inputLabel">Description</label> <textarea cols="40" rows="3" name="description" id="description" class="txtInput">[[!+grow.description]]</textarea> <span class="applyError">[[!+fi.error.description]]</span> </li> <li class="fieldOuterBox"> <label for="image" class="inputLabel">Leader Image</label> <input type="text" name="leader_url" id="leader_url" value="[[!+grow.leader]]" /> <a name="submit" class="btnSmall" onclick="leaderUploadPopup();" href>Select Image</a> <br class="clear" /> <label for="image" class="inputLabel"> </label> <img src="[[!+grow.leader]]"> <span class="applyError">[[!+fi.error.tags]]</span> </li> <li class="fieldOuterBox"> <label for="tags" class="inputLabel">Tags</label> <input type="text" name="tags" id="tags" class="txtInput" value="[[!+grow.tags]]" /> <span class="applyError">[[!+fi.error.tags]]</span> </li> <li class="fieldOuterBox"> <label for="publish_on" class="inputLabel">Publish On (optional)</label> <input type="text" name="publish_on" id="publish_on" class="txtInput" value="[[!+grow.publish.date]]" /> <span class="applyError">[[!+fi.error.publish_on]]</span> </li> <li class="fieldOuterBox"> <label for="publish" class="inputLabel"> </label> <input type="checkbox" name="published" id="published" class="checkboxInput" value="1" [[!+grow.published]]/> <span class="">Published</span> </li> <li class="fieldOuterBox vWrapper"> <label for="submit" class="inputLabel"> </label> <a name="submit" class="btnSmall" onclick="form.submit();">Save Grow</a> </li> </form> <div class="cropBox"> <div> </div> </div> <script> $( "#publish_on" ).datepicker({ inline: true }); </script>
This question has been answered by whitebyte. See the first response.
<a name="submit" class="btnSmall" onclick="form.submit();">Save Grow</a>
<input type="submit">
<a name="submit" class="btnSmall" onclick="form.submit();">Save Grow</a>
Why this? Try to make standart submission
<input type="submit">
and check this out
I had a problem with this before but I solved it by removing the href from my link that submits the form. I tried replacing the <a> with a submit button, but it's still not invoking the hook.
<button>Submit</button>
[[!FormIt? &hooks=`redirect` &redirectTo=`1` ]] <form name="form" id="form" action="[[~[[*id]]]]" method="post" class="form"> <input type="hidden" name="owner_id" id="owner_id" value="[[!+modx.user.id]]"> [[!+grow.id.field]] <li class="fieldOuterBox"> <label for="title" class="inputLabel">Title</label> <input type="text" name="title" id="title" class="txtInput" value="[[!+grow.title]]" /> <span class="applyError">[[!+fi.error.title]]</span> </li> <li class="fieldOuterBox"> <label for="description" class="inputLabel">Description</label> <textarea cols="40" rows="3" name="description" id="description" class="txtInput">[[!+grow.description]]</textarea> <span class="applyError">[[!+fi.error.description]]</span> </li> <li class="fieldOuterBox"> <label for="image" class="inputLabel">Leader Image</label> <input type="text" name="leader_url" id="leader_url" value="[[!+grow.leader]]" /> <a name="submit" class="btnSmall" onclick="leaderUploadPopup();" href>Select Image</a> <br class="clear" /> <label for="image" class="inputLabel"> </label> <img src="[[!+grow.leader]]"> <span class="applyError">[[!+fi.error.tags]]</span> </li> <li class="fieldOuterBox"> <label for="tags" class="inputLabel">Tags</label> <input type="text" name="tags" id="tags" class="txtInput" value="[[!+grow.tags]]" /> <span class="applyError">[[!+fi.error.tags]]</span> </li> <li class="fieldOuterBox"> <label for="publish_on" class="inputLabel">Publish On (optional)</label> <input type="text" name="publish_on" id="publish_on" class="txtInput" value="[[!+grow.publish.date]]" /> <span class="applyError">[[!+fi.error.publish_on]]</span> </li> <li class="fieldOuterBox"> <label for="publish" class="inputLabel"> </label> <input type="checkbox" name="published" id="published" class="checkboxInput" value="1" [[!+grow.published]]/> <span class="">Published</span> </li> <li class="fieldOuterBox vWrapper"> <label for="submit" class="inputLabel"> </label> <input type="submit" name="submit" id="submit" value="Save Grow" /> </li> </form> <script> $( "#publish_on" ).datepicker({ inline: true }); </script>
How can I test the &submitVar parameter?
<input type="submit" name="somename">
&submitVar=`somename`