Get the form fields to content folder from on the front end

Hi everyone

I have working on new project with my client. Let me explain what i need.

  • Visitors will come to register to website. And they will enter their info via form. (name, surname, etc.)
  • When they finish to fill in form, they will click to ‘save’ button and their information will save our Kirby ‘content/registers’ folder. As a panel but this time it must be on front end.
  • After that i want to get all users info from ‘content/registers’ to panel. Administrator will see the registers in the form of list. Administrator will able to change and modify registers information.

How can i do it? especially get to visitors info from front end to content/registers.

I am not sure if I get it right…
Do you wish to filter content if users are not logged in?

If so, you could just let kirby control your accounts and do something like this:

if(empty(site()->user())){
    // user not logged in while "empty" is true...
} else {
	// do user 'logged in' stuff...
}

This requires kirby users to be created. I am not sure if this works with “read txt, filter user, check password” method, you are suggesting.

If I am not mistaken you are planning to save user logins in plain text to ‘content/registers’, this might be not the best option, if not encrypted & stuff…

why not let kirby do the user administration?
This would require kirby to have user roles, though (no panel for ‘readers’).
be sure to check this, too:
http://getkirby.com/docs/cheatsheet/user/has-role
http://getkirby.com/docs/cheatsheet/user/is

Hi Thank you for your helping

I just want to get users informations without login. Only They will fill in form and save their info in ‘content/registers’ folder, they will leave their info to us. We will keep their info in ‘content/registers’ folder.

Regards

Ah, I see… Like collecting email adresses and information for newsletters, etc.?

I believe that this would just require a form and the handling with file operations.
http://getkirby.com/docs/toolkit/api/f/append

Just grab the html form content and append it to a file.
With json you are able to grab the data and work with it from the file.

I saw something similar within the comments plugin: https://github.com/vladstudio/vladstudio-kirby-comments

perhaps you can grab some ideas from there.

Even better: You could use the comments plugin for this.
Just use the form to add information to a specific page/folder.
It saves any information submitted in a form to a .json file which can be used for your purposes.

Be sure to take this version if you are on Kirby 2:

Or you could create a subpage to registers for each submission.
Have a form in a front-end template registers.php and use a page controller to save the submitted data.

You can get your form data within the controller with:

get('fieldname');

And to create/update a page you can do something similar to this:

try {
          page('registers/'.get('name'))->update(array(
              'title'    => get('name'),
              'degree'   => get('degree'),
              'email'    => get('email')
          ));
          $error = false;

        } catch(Exception $e) {
            $error = true;
            echo 'The user could not be updated';
            echo $e->getMessage();
        }

Not that you should not actually create/update the subpage with the direct from field data, but first have some validation on it. It’s just like this in there to simplify the example.

The benefits of this way are that you can easily add a blueprint to access that data conveniently through the panel.

2 Likes

Thank you very much Andi!
I will try it.

Also i guess this will help to me ;

1 Like

Yep Nico very nice way

Thank you very much!

Hey sorry to revive such an old topic. Would you be willing to share your final code @aristotheme ?
I’m looking for a similar solution and may as well not reinvent the wheel :slight_smile: