Not logged in. · Lost password · Register

All posts by Gunnar (6)

topic: How to use the Script Mode in the Bureaucracy Plug-in (A short tutorial on saving data from the Bureaucracy forms using a self-made PHP script)  in the forum: General Help and Support Plugins
Avatar
Gunnar #1
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: How to use the Script Mode in the Bureaucracy Plug-in
How to use the Script Mode in the Bureaucracy Plug-in

Hello,

The Bureaucracy Plug-in (https://www.dokuwiki.org/plugin:bureaucracy) is an easy to use tool to create forms quickly. For beginners, the Mail Mode is both powerful and easy to use.

The description of the Plug-in gives a very short example of how to use a script processing with the entered data – Script Mode – yet this is not suitable for programmers on beginner's level. I want to give a more lengthy example here, covering how to pre-fill the form with data from a database, show the form itself, and save the data using a script.

Pre-filling the form

Pre-filling a form is easy using a Wiki link where the field names are enclosed by @-signs:

[[playground:bureaucracy_test?@name@=Säßerich&@username@=saserich]]

Here, the form is on the page playground:bureaucracy_test, and the transmitted fields are name and username. The field name will be filled with “Säßerich”, the field username will be filled with “saserich”.

However, this won't help if you want to pre-fill the form dynamically from a database. The trick is: We can generate an URL directly which should look somewhat like:
http://localhost/dokuwiki/doku.php?id=playground:bureaucracy_test&@name@=S%C3%A4%C3%9Ferich&@username@=saserich
We have to use rawurlencode() to encode the variable content. Here is a tiny script that encodes all variables, creates the full URL, and finally redirect to the form which will appear pre-filled. This script should be placed somewhere outside the DokuWiki folder, for example, in the root folder of the website (e.g., /httpdocs).

<?php    // filename: put_data_for_bureaucracy_form.php

// Switch on error reporting on display. Remove in production!
error_reporting(E_ALL);
ini_set('display_errors', 'On');

// We can fetch some data from somewhere, such as, a database
$data = array(
    'name' => 'Säßerich',
    'username' => 'saserich'
);

$baseurl = 'http://localhost/dokuwiki/doku.php?id=playground:bureaucracy_test';
$get_vars = "";

foreach ($data as $key => $value) {
    $get_vars .= '&@' . $key . '@=' . rawurlencode($value);
}
   
$url = $baseurl . $get_vars;

// Now redirect to the pre-filled form
header("Location: $url");

We simply call http://localhost/put_data_for_bureaucracy_form.php and the form will open which was stored at http://localhost/dokuwiki/doku.php?id=playground:bureaucracy_test:


====== Bureaucracy Plug-in Example ======

<form>
action script get_data_from_bureaucracy_form.php
labels :lang:namespace:form_labels

fieldset "Account"
textbox "username" /^[A-Z]{1,8}$/ "**Username must have 8 characters A~Z"
password "password"

fieldset  "Limit access by IP addresses"
select "ip_action"  "list|add|remove"

fieldset  "Add new IP addresses" "ip_action"  "add"
textarea "ip_addresses" x3

fieldset  "Remove IP addresses" "ip_action"  "remove"
textarea "ip_addresses" x3

fieldset ""
submit "submitbutton"
</form>

The translations for the labels should be stored at :lang:namespace:form_labels where lang can be the language, e.g. eo for Esperanto, see the wonderful translation plug-in, https://www.dokuwiki.org/plugin:translation. namespace can be any DokuWiki folder (better: namespace). We can skip that by now, this just generates an error message and will display the “naked” label names as given. Tip: The last fieldset has no title, giving a nice separated box containing just the submit button. This example shows a tiny example of Regular Expressions: The entered username must be DOS-like: 8 letters A~Z only. The "Add new IP addresses" or "Remove IP addresses" sections are only shown when the corresponding ip_action has been selected. To achieve this, the 3rd parameter of the fieldset ("add", "remove") must match with ip_action contents.

Now let's look at the script storing the form data. This script has to be stored in conf/plugin/bureaucracy/, e.g.

/home/user/public_html/dokuwiki/conf/plugin/bureaucracy/get_data_from_bureaucracy_form.php

<?php    // filename: get_data_from_bureaucracy_form.php

// Switch on error reporting on display. Remove in production!
error_reporting(E_ALL);
ini_set('display_errors', 'On');


use dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface;

class bureaucracy_handler_get_data_from_bureaucracy_form implements bureaucracy_handler_interface {

    public function handleData($fields, $thanks)
    { // extracts the form data into an PHP array and into a JSON string   
        $data = array();
        foreach($fields as $field) {
            if ($field->getFieldType() == 'fieldset') { } else {
                $value = $field->getParam('value');
                $label = $field->getParam('label');
                if($value === null || $label === null) {  } else { $data[$label] = $value; }
            } // if
        } // foreach
       
        // Just for demonstration, we will display the array. Remove in production!
        echo '<hr><p>$array=</p>';
        print_r($data);
        echo "</p><hr>";
       
        // If you work entirely locally, you can now call e.g. a routine storing this $array in your SQL database.
       
        // Preparing JSON. The data given by DokuWiki are already UTF-8 encoded which is required by JSON.
        $json_string = rawurlencode(json_encode($data));
       
        // Save data on some server
        $result = file_get_contents('https://www.example.com/?q=' . $json_string);
        // After receiving the data, the other server sends back "1" if successful.
        if ($result == 1) { $thanks = "Your profile has been updated.";  } else { $thanks = "Something went wrong."; }
        return $thanks;
        } // function handleData
} // class


Some remarks: I did not include any variable check / data filtering. Always make sure that data posted by an evil user cannot cause any harmhttp://php.net/manual/de/function.filter-var.php For example, you shouldn't rely on the username just having 8 letters, although it should be filtered by DokuWiki this way.

I hope this example will be helpful for hobby programmers like me  :-)

My special thanks to user Michaelsy who pointed me to the dynamic pre-filling of the forms!

Greetings,

Gunnar
topic: pre-filled FORMs mit dem Bureaucracy Plug-in? (pre-filled fields, PHP, SQL, Bureaucracy Plug-in)  in the forum: Non-English Discussion German discussion
Avatar
Gunnar #2
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: pre-filled FORMs mit dem Bureaucracy Plug-in?
Hallo!

Nachdem ich die umfangreiche Dokumentation gelesen habe, bin ich so schlau als wie zuvor  :'( , deswegen hier meine (überflüssige?) Frage (verbunden mit der Bitte auf die richtige Stelle in der Dokumentation):


Gegeben ist eine SQL-Datenbank, in der (teilweise veraltete) Daten enthalten sind.

Aufgabe: Einen Datensatz aus der Datenbank lesen und in die richtigen Felder einer Bureaucracy Form befüllen.

Die reine Bureaurcracy Form sähe so aus:
<form>
action script write_to_db.php
labels :de:update_form_labels
thanks "Thank you for updating your contacts!"

fieldset "namefields"
textbox "hospitalname"
textbox "phone"
email "email"
textbox "sedamo"
submit "submitbutton"
</form>

Der Benutzer ruft den Update-Link auf:
https://www.sos-card.net/update?key=4711

Und das von DokuWiki generierte Formular beinhaltet schon die (alten) Werte:

<p>
Name des Krankenhauses:
<input type="text" name="hospitalname" value="Kölner Unikliniken">
</p>



In reinem PHP hätte ich das so gelöst:

<input type="text" name="hospitalname" value="<?php echo $hospital_name; ?>">

Aber leider klappt das Umschalten in den <PHP>-Modus innerhalb eines Bureaucracy Formulars nicht, soll heißen:

textbox "hospitalname" <PHP>echo $hospital_name;</PHP>

geht nicht :-)

Wie bekomme ich das am elegantesten gelöst?

/Gunnar
topic: HTTPS-Umschalter (HPPTS, SSL, Kontaktformular, sichere Verbindung,)  in the forum: Non-English Discussion German discussion
Avatar
Gunnar #3
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: HTTPS-Umschalter
Hallo!

Die Seite von The SOS Card Project ist absichtlich nicht (nur) über HTTPS erreichbar, denn in manchen Ländern sind diese „unüberwachbaren“ Seiten blockiert oder laden zumindest erheblich langsamer als die „reinen“ HTTP-Seiten. Nun möchte ich auf der „Kontakt“-Seite einen „Umschalter“ einbauen, mit dem von (z.B.) http://www.sos-card.info/wiki/de/contact auf https://www.sos-card.info/wiki/de/contact gewechselt werden kann. Ich möchte dies, wenn möglich, aber nicht „hard coding“ eintragen als [[https://www.sos-card.info/wiki/de/contact]]. Gibt es da eine elegante Lösung? Bei der der Umschalter sogar verschwindet, wenn man schon eine HTTPS-Verbindung hat?
Grüße
Gunnar
topic: More social links for the Socialite plug-in  in the forum: General Help and Support Plugins Plugin Wishlist
Avatar
Gunnar #4
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
In reply to post ID 61566
Hello Myron!

You wrote:

Quote by turnermm:
You should post this to the author's issues page:
https://github.com/fa-ribeiro/dokuwiki-plugin-socialite/is…

Thank you for this advice; unluckily, GITHUB is now using inserts from Google, which is blocked in China: I cannot open that page. Can you please copy the link to this discussion here into the Github discussion section?

Kind regards,

Gunnar
topic: More social links for the Socialite plug-in  in the forum: General Help and Support Plugins Plugin Wishlist
Avatar
Gunnar #5
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: More social links for the Socialite plug-in
Hello!

I am referring to:
PLUG-IN: socialite
VERSION: Last updated on 2018-04-09

The Socialite plug-in adds responsive lightweight social share buttons anywhere on page (URL: https://www.dokuwiki.org/plugin:socialite)

The inevitable (i.e., US-American) social media services are covered. Here some more links; maybe someone can add them to a new version of Socialite?

$theURL is the URL which should be shared;
$theTitle is the title of the shared link;
$theDescription is a short explanation to the shared link.

<a href="http://like.baidu.com/set?buttontype=small&cb=bdShare.ajax._callbacks.bd4bb141b&index=0&url=<?php echo $theURL; ?>" target="_blank"><img src="/PATH_TO_IMAGE/baidu.png" alt="Baidu"></a>
<a href="http://service.weibo.com/share/share.php?url=<?php echo $theURL; ?>&appkey=&title=<?php echo $theTitle; ?>&pic=&ralateUid=&language=zh_cn" target="_blank"><img src="/PATH_TO_IMAGE/sina.png" alt="Sina Weibo"></a>
<a href="http://www.digg.com/submit?phase=2&url=<?php echo $theURL; ?>&title=<?php echo $theTitle; ?>" target="_blank"><img src="/PATH_TO_IMAGE/digg.png" alt="Digg"></a>
<a href="http://del.icio.us/post?url=<?php echo $theURL; ?>&title=<?php echo $theTitle; ?>&notes=<?php echo $theDescription; ?>" target="_blank"><img src="/PATH_TO_IMAGE/delicious.png" alt="Delicious"></a>
<a href="http://www.newsvine.com/_tools/seed&save?u=<?php echo $theURL; ?>&h=<?php echo $theTitle; ?>" target="_blank"><img src="/PATH_TO_IMAGE/newsvine.png" alt="Newsvine"></a>
<a href="http://www.evernote.com/clip.action?url=<?php echo $theURL; ?>&title=<?php echo $theTitle; ?>" target="_blank"><img src="/PATH_TO_IMAGE/evernote.png" alt="Evernote"></a>
<a href="http://www.friendfeed.com/share?url=<?php echo $theURL; ?>&title=<?php echo $theTitle; ?>" target="_blank"><img src="/PATH_TO_IMAGE/friendfeed.png" alt="Friendfeed"></a>

Annotations to the first two links:

Baidu.com is the “Chinese Google”. It is the most popular web-search in China.
Weibo.com is the “Chinse Twitter”. It is a microblogging website.


I hope this helps to easily implement some new links. I can easily provide icons (PNGs) for the above-given social media platforms.

Greetings,

Gunnar
topic: Greetings from China  in the forum: Community User Introductions
Avatar
Gunnar #6
Member since Jul 2018 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Greetings from China
Hello!

Greetings from Hangzhou, the paradise on earth :-)

My name is Gunnar Lindenblatt, I am a medical physicist. Here at the Hangzhou International Christian Fellowship (HICF), we started The SOS Card Project: We create a multilingual emergency ID. In case of a medical emergency, the local (here: Chinese) paramedic can read the information (here: in Chinese ;-) ) and provide better help. The website at URL: http://www.sos-card.info/ is run by DokuWiki, of course, and we are making good use of the Translation Plug-in.

Thanks to all developers of DokuWiki, the DokuWiki themes and the DokuWiki plug-ins!

Greetings,

Gunnar
Close Smaller – Larger + Reply to this post:
Special characters:
Special queries
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-11-20, 01:25:03 (UTC +01:00)