Jump to content

Is there a proper way to learn about CSM application development?


sam13579
 Share

Recommended Posts

Like most of the people I started with WordPress. But for some reason WordPress was too hard for me. Then I found Processwire and it seems very easy for me. But still I have some problems with many small things. I think programming is mostly about input, output and how do we process things. But I am facing many holes now and then in the tutorials.  I am going to give some specification:

1. I found a tut where form submission was demonstrated . There I found that there is a special way to get the form input. It was with processInput() method. But that method is not working correctly.

2. I found no specification about how I save a form data into database .

3. I have to use  $this->modules->get() , $modules->get()

I think I will face many more problems later. What is wrong with me? Am I too beginner for this? Or am I missing something?

Link to comment
Share on other sites

Most of us have been through this. You start not knowing anything  and do most of things by trial and error. But at the end you come out stronger and more knowledgeable. I do not think there is a shortcut here. To learn something is to find yourself in the place of ignorance first.

You should solve your tasks one by one, searching the forum, reading the code, asking the community if you get stuck. I do not think anyone is "too beginner". But everyone has to start from where he is at. There are a lot of docs, great forum posts and other resources spread around. but there is probably not a single tutorial to complete and become a ProcessWire master.

Take you time, be patient, have fun along the way))

P.S. And just to address you specific questions a bit, I would recommend you this link... and many more here - just search for "create form")))

  • Like 6
Link to comment
Share on other sites

Quote

1. I found a tut where form submission was demonstrated . There I found that there is a special way to get the form input. It was with processInput() method. But that method is not working correctly.

While the first link provided by @Ivan Gretsky seems like a good starting point for creating forms with InputfieldForm, note that this is not exactly the simplest thing to do. Personally I've never found it very intuitive, or very useful for that matter. (This, of course, is a highly opinionated statement — so take it with a grain of salt.)

In my opinion it's almost always easier to just create a basic HTML form:

<form action="." method="POST">
    <label for="your_name">Your name</label>
    <input type="text" name="your_name" id="your_name">
    <input type="submit">
</form>

... and then process form input in the template file:

<?php namespace ProcessWire;

if ($input->post->your_name) {

    // always sanitize user input (https://processwire.com/api/ref/sanitizer/)
    $your_name = $sanitizer->entities($your_name);

    // do something with input
    echo "<p>Hi " . $your_name . "! What's up?</p>";
}

Of course that's a super-simplified example, but hope you get the point. Using InputfieldForm, InputfieldText, InputfieldSubmit etc. is doable, but in many cases they mainly just add a whole new layer of complexity without much actual benefit ?

Quote

2. I found no specification about how I save a form data into database .

If you want to save values to custom database tables, you need to work with "raw" SQL through the $database object.

But here's the kicker:

  • The preferred way to save data in ProcessWire is through pages. A "page" is essentially a general purpose data storage object: you can use pages to store publicly viewable (front-end) content, as well as (back-end only) categories or tags, or form entries — or really whatever it is that you need to store.
  • The API is largely built around working with pages: creating, finding, reading, modifying, and deleting them. Again: you can work directly with database tables through the $database object, but that's not really what ProcessWire was built for. (It's useful for special situations, but for a beginner that's not what I would recommend starting with.)

As such, likely the easiest way to save data would be to create a template with fields related to your entries, and then on each form entry creating, populating, and saving a page using that template. That's not necessarily scalable if you expect tens or hundreds of thousands of entries in a short period of time, but apart from that it will work just fine ?

... although, to be fair, a lot of folks just use Form Builder for building and managing forms. It's a commercial module, but in the long term it saves so much time and makes things so easy that it's well worth it. Especially if you're working on projects that you get paid for.

Quote

3. I have to use  $this->modules->get() , $modules->get()

This depends on the context: if you're writing code in a template file (/site/templates/some-template.php) then you can use $modules. If you're writing code within a class that extends the Wire object — module, Page class, etc. — then you need to use $this->modules instead. And if you're writing code within a module, you generally use wire('modules'), etc.

Here's a docs page explaining when to use what: https://processwire.com/docs/start/api-access/.

  • Like 3
  • Thanks 2
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...