How to collect data in a form, save it to an external (not the concrete5) db, then retrieve the data

Newbie! Hi, I am an experienced developer but new to concrete5. I am going to be building a site that will collect demographic information on students and allow them to register to take certification exams and eventually the scores for the exams they took and their certifications they hold from this company will be stored and all this will be searchable. I will also need to store the exam information for all exams that the company hosts - who are all the students that attended, date, time, location, etc.

I believe this can be accomplished with concrete5 but I just want to be sure before I dive too far in. What are some good approaches to this - custom blocks? I am a little fuzzy on where the sql code lives that is executed on submit of the form? Can anyone provide a pointer to some good directions on how to accomplish this or better yet some code examples for a form submission and/or query to retrieve data?

I've always built the site, and deployed it on a server, no CMS involved! This is a little new to me and I'm struggling to wrap my brain around implementing something more complex than a brochure site.



View Replies:
Mainio replied on at Permalink Reply
Hi Jennifer,

Your question is so wide-ranged that I'm not surprised it has 0 answers. I'll try to cover some of it here but surely it's too wide of a subject to cover in only a single reply.

One thing I can point to is the how-tos available on this site, there are a lot of them and you can usually find links to them just by googling the subject of your problem.

First of all, the form block I thin you're referring to, might not be your best friend in implementing such a thing. I'll cover this part a bit later but let's start with the basics.

To answer your question: generally all SQL stuff lies in the models layer of the MVC architecture concrete5 uses. More about the topic:

However, there are some exceptions to this convention because concrete CMS as an application is over 10 years old and some code is still quite ancient. And one of these code points happens to be the form block, so you'll find the form block's entry saving SQL straight from the form block's controller:

Then when you open this file, you'll notice it only contains empty classes. This is because concrete5.6 provides this kind of overriding structure so that modifications to these classes could be managed more easily. The actual code for the classes they extend can be found from the /concrete/core folder.

More about the stub classes:

And if you want to override, i.e. customize some of the code found in the core (inside the /concrete folder), you'll need to follow the override structure. It means that you should never touch directly any file that lies in the /concrete folder itself.

More about overrides:

And to answer the question in the title of this article, please see this guide on connecting to external databases (see "Connecting to Other Databases"):

So, that's that, should give you answer to your basic questions but the problem domain still remains unsolved for your problem. So, here's some suggestions on the implementation:
- Don't use the form block, it's meant to be a basic form to collect data and save it in a custom dataset, not something you should be using when creating custom models or some custom functionality. You could create a completely new block based on the form block but I would advice against it simply because of how the code of that block looks like (it does not necessarily guide a novice concrete5 developer to the right track, instead it gives you a bunch of bad ideas).
- Don't use the external system if all it does is described in this post. While it often makes sense using some existing code base, the problem sounds rather simple to solve so I would see using the old system would only cause a kludged solution that is hard to maintain. This is of course if the other system does not have any proper integration APIs available as I would guess based on the description. Instead, I would suggest creating a native concrete5-based system OR if it is necessary to use the old system e.g. because of administrative reasons, I would suggest creating a proper integration API to that application if not already available.

Then for the actual implementation:
- Create a custom backend for the whole architecture you need, i.e. models like Exams, Registeration, Student, StudentExamAttendance, StudentExamScore, etc.
- Create a custom block to collect the registrations and store them accordingly to your new backend
- Create the proper dashboard views to manage all the non-visitor related database stuff, e.g. exam dates and scores

And if you can use the old system you're referring to, through a proper integration API, you can skip part of the backend implementation but you'll still need integration classes of the similar format that connect to your API and send/fetch the data.

Hopefully this helps you out at least on some aspects of your problem scope and gives you a good start to become the next great concrete5 developer.

Antti / Mainio