Skip to content

Commit

Permalink
Fix form-submission problem (issue #1). Change from a POST form which…
Browse files Browse the repository at this point in the history
… has its action changed at submit-time, to a GET form which has a hidden id field which is changed at submit-time. Also submit to the full DOKU_SCRIPT location, rather than just DOKU_BASE, because index.php doesn't forward query string.
  • Loading branch information
samwilson committed Mar 12, 2013
1 parent a98ad79 commit 447a488
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugin.info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
base addnewpage
author iDo, Sam Wilson, Michael Braun
email
date 2013-03-06
date 2013-03-12
name Add New Page
desc Adds a "new page form" to any wiki page.
url http://www.dokuwiki.org/plugin:addnewpage
17 changes: 12 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ jQuery(document).ready(function() {
}
});

// Change the form's action on submit
// Change the form's page-ID field on submit
$editform = jQuery(".addnewpage form").submit(function(e) {
var ns = jQuery(this).find("[name='np_cat']").val();
var title = jQuery(this).find("input[name='title']").val();
var action = DOKU_BASE+"?do=edit&id="+ns+":"+title;
jQuery(this).attr("action", action);

// Build the new page ID and save in hidden form field
var ns = jQuery(this).find("[name='np_cat']");
var title = jQuery(this).find("input[name='title']");
var id = ns.val()+":"+title.val();
jQuery(this).find("input[name='id']").val(id);

// Clean up the form vars, just to make the resultant URL a bit nicer
ns.attr("disabled", "disabled");
title.attr("disabled", "disabled");

return true;
});

Expand Down
6 changes: 4 additions & 2 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getInfo() {
return array(
'author' => 'iDo, Sam Wilson, Michael Braun',
'email' => '',
'date' => '2013-03-06',
'date' => '2013-03-12',
'name' => 'addnewpage',
'desc' => 'Adds a "new page form" to any wiki page.',
'url' => 'https://wiki.dokuwiki.org/plugin:addnewpage',
Expand Down Expand Up @@ -66,9 +66,11 @@ function render($mode, &$renderer, $data) {

$button_val = ((@$this->getLang('okbutton')) ? $this->getLang('okbutton') : 'ok');
$form = '<div class="addnewpage">'.DOKU_LF
.DOKU_TAB.'<form name="addnewpage" method="post" accept-charset="'.$lang['encoding'].'">'.DOKU_LF
.DOKU_TAB.'<form name="addnewpage" method="get" action="'.DOKU_BASE.DOKU_SCRIPT.'" accept-charset="'.$lang['encoding'].'">'.DOKU_LF
.DOKU_TAB.DOKU_TAB.$ns_select.DOKU_LF
.DOKU_TAB.DOKU_TAB.'<input class="edit" type="text" name="title" size="20" maxlength="255" tabindex="2" />'.DOKU_LF
.DOKU_TAB.DOKU_TAB.'<input type="hidden" name="do" value="edit" />'.DOKU_LF
.DOKU_TAB.DOKU_TAB.'<input type="hidden" name="id" />'.DOKU_LF
.DOKU_TAB.DOKU_TAB.'<input class="button" type="submit" value="'.$button_val.'" tabindex="3" />'.DOKU_LF
.DOKU_TAB.'</form>'.DOKU_LF
.'</div>';
Expand Down

0 comments on commit 447a488

Please sign in to comment.