Jump to content

How to use pw to create a guestbook like functionality ?


adrianmak
 Share

Recommended Posts

Instead of ordinary CMS function, I would like to add a guestbook function on a pw's website.

I will create a front-end public form, for users to submit comments/messages

Messages are not open to public. To read users'  messages, it required to login to pw's backend.

It easy to use pw's core page api (under a specific page) to store users submitted messages.

However in the guestbook scenario, it is not user friendly in to ordinary page tree UI, to show all submitted messages.

I would like the UI looks like, when clicking the page, it will presented in a table view with a pages

A_iGWqnfN.png

Link to comment
Share on other sites

Ahh! Got it! You need an admin interface to easilly manage those guestbook submissions.

1) BernhardB's listerpro suggestion is what you want to go for if you have the option to use this paid module. It is really powerfull.

2) You could build a process module to list all guestbook submission for free, but you need to get your hands dirty with code :). You can take a look at something like this for an inspiration:

class GuestBook extends Process {
	public function init() {
		parent::init(); // always remember to call the parent init
	}

	public function execute() {
		$out = '';	
		$table = $this->modules->get("MarkupAdminDataTable");
		// Table header
		$table->headerRow( ["Name of submission", "By whom...", ...] );
		// Selector to get all your guestbook submissions
		$listing = $this->pages->find("...");
		foreach ($listing as $page) {
			$data = array(
				// A td with the link to edit the page (you need to change the ... part)
				$page->title => $this->config->urls->admin . ".../edit/?id=" . $page->id,
				$page->created_by,
				...
			);
			$table->row($data);
		}
		$out .= $table->render();
		$pagination = $listing->renderPager();
		$out .= $pagination;
		return $out;
	}	

	public function executeEdit() {
		// Write code to edit submission
	}
// ...
}

  • Like 6
Link to comment
Share on other sites

you can use datatables and a bit of coding and easily achieve what you want if you want I will make a sample for you.

I'm appreciated if you could show a sample.

Actually, I am thinking of, instead of using pw's page api, could i use something like pw's raw database api  (exist?) to insert and read a db table.

The submitted messages on the page tree is not necessary to show to back-end.

Link to comment
Share on other sites

I dont know what you exactly need in your guestbook but why dont you use the comment field as a guestbook? You can style it in the way you want with overrides.

What is so special about the comment field in this matter ? You can pull the contents of any field and css style it through the html thags that surround the the echoed field.

Edit: Ah I see now, I posted too early.

https://processwire.com/api/fieldtypes/comments/

Link to comment
Share on other sites

I dont know what you exactly need in your guestbook but why dont you use the comment field as a guestbook? You can style it in the way you want with overrides.

I think the name guestbook, which is used in a client's old website (he wanted to revamp the website).

After explained by client, the functionality he wanted, is a enquiry form.

As I said from OP, the form is open for public to ask information about product.

Instead of submitting the form data to a designate email address, the form data will store in database for admin to read.

Link to comment
Share on other sites

As I said from OP, the form is open for public to ask information about product.

Instead of submitting the form data to a designate email address, the form data will store in database for admin to read.

Form Builder has this functionality. Form submissions can be displayed in a table in the PW admin or saved as pages.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

I'm now heading to writing the module

For simplicity purposes, just display a text

class GuestBook extends Process {
	public function init() {
		parent::init();
	}

	public function execute() {
		$out = '';	
		$out = "Guestbook back-end";
		return $out;
	}	

	public function executeEdit() {
		// Write code to edit submission
	}
// ...
}

I went to back-end to install it and pw returned

Error: Class 'GuestBook' not found (line 407 of /var/www/html/pw272/wire/core/Modules.php)

Link to comment
Share on other sites

Your module is missing

public static function getModuleInfo() {
    return array( /* title, version, summary and autoload values*/ )
};

It's is not working.

	public static function getModuleInfo() {
		return array(
			'title' => 'GuestBook', 
			'version' => 2, 
			'summary' => 'Manage Guestbook submission.',
			'autoload' => true
			);
	}
Link to comment
Share on other sites

I deleted the old file and create a new one. Works now.

By the way, when module installation, it should add a page in under the "Admin" page automatically.

I added two method to call the parent install and uninstall method

    public function install() {
        return parent::___install();
    }
    
    public function uninstall() {
        return parent::___uninstall();
    }

But no page is added under 'Admin'  page.

Link to comment
Share on other sites

You have something like this: ?

public static function getModuleInfo() {
    return array(
        'title' => 'Your title',
        'summary' => 'What you want to say.',
        'version' => '0.0.7',
        'author' => 'adrianmak',
        // Do you have this ?
        'page' => array(
            'name' => 'yourname',
            'parent' => 'setup',
            'title' => 'Your title',
            ),
        );
}
BTW, When you don't do anything in public function install() or uninstall, you don't need to use them... Edited by Martijn Geerts
Damn LostKobrakai, he's way to quick.... :-)
Link to comment
Share on other sites

Understood. For the purpose of showing up an module navigation in the pw top admin menu, just put a page array as shown in the above post, pw will create it automatically.

The install and uninstall method is not necessary in this case.

By the way, I found some other module declare execute method in public function ___execute() { }

what is the different with or without three underscore prefix ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...