Skip to content

Commit

Permalink
new form handling draft
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienli committed Nov 12, 2021
1 parent 21b6b32 commit fe03c33
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ function getInfo(){
function register(Doku_Event_Handler $controller) {
$controller->register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handleTplActUnknown', array());
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActPreprocess', array());
$controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'handle_profile_form', array());
$controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'handle_profile_form', array()); //old form
$controller->register_hook('FORM_UPDATEPROFILE_OUTPUT', 'BEFORE', $this, 'handle_profile_form', array()); //new form
}

/*
* Add a field for RTM import email
*/
function handle_profile_form(&$event, $param){
global $INFO;

if (empty($_SERVER['REMOTE_USER'])) {
return; // Not logged in
}
Expand All @@ -58,23 +59,32 @@ function handle_profile_form(&$event, $param){
$rtm_form.= '<input type="reset" value="Reset" class="button" />';
$rtm_form.= '</fieldset>';
$rtm_form.= '</div></form>';
$pos = $event->data->findElementByAttribute('type', 'reset');
$event->data->insertElement($pos+3, $rtm_form);

$form = $event->data;
if (is_a($form, \dokuwiki\Form\Form::class)) {
// new form, still using old HTML generated code instead of objects
$pos = $form->findPositionByAttribute('type', 'reset');
$form->addHTML($rtm_form, $pos);
} else {
// old form in html
$pos = $event->data->findElementByAttribute('type', 'reset');
$event->data->insertElement($pos+3, $rtm_form);
}
}


function handleActPreprocess(&$event, $param){
if($event->data == 'plugin_rtmsend'){
// Accept the action
$event->preventDefault();
$event->stopPropagation();
return;
return;
}
else if($event->data == 'rtmemailregister') {
// Accept the action
$event->preventDefault();
$event->stopPropagation();
return;
return;
}
else {
// nothing to do for us
Expand All @@ -84,13 +94,13 @@ function handleActPreprocess(&$event, $param){
}

/**
* Hook for event TPL_ACT_UNKNOWN, action
* Hook for event TPL_ACT_UNKNOWN, action
*/
function handleTplActUnknown(&$event, $param) {
if ($event->data == 'plugin_rtmsend') {
global $INPUT; //available since release 2012-10-13 "Adora Belle"
global $INFO;

$wikitext = "=== ".$this->getLang('Results')." ===\n";
if(!checksecuritytoken()) {
return;
Expand All @@ -116,14 +126,14 @@ function handleTplActUnknown(&$event, $param) {
// send the mail
if(mail_send($rtmEmail,
"", // no title
$tasksList)) {
$tasksList)) {
$sendResult = true;
}

// Accept the action
$event->preventDefault();
$event->stopPropagation();

// show final result
if($sendResult)
$wikitext.= $this->getLang('checklist_sent');
Expand All @@ -137,7 +147,7 @@ function handleTplActUnknown(&$event, $param) {
}
else if($event->data == 'rtmemailregister') {
global $INPUT; //available since release 2012-10-13 "Adora Belle"

if(!checksecuritytoken()) {
return;
}
Expand Down

0 comments on commit fe03c33

Please sign in to comment.