Resource FormIt field with select option from a custom database table

What is the easiest way to have a dropdown / listbox to be able to select an option from a custom database table. I realise there is the select binding for template variables but I would like to have a simple snippet to create a dropdown / listbox for use in a form. I am currently exploring using FormIt to create the form and store data in my custom table.

The reason behind the question is that I want to have a form to create “players” to a custom table and I want the facility to query the custom table and check that the “player” is not duplicated and also to either create a new “player” or amend an existing “player”.

I am not experienced at php coding nor familiar with Migx, so any examples would be appreciated even if the example use these codings as I may be able to use them to understand them better.

Thanks

If you are planning to use MIGXdb for your custom database table or have a model/schema for it, you can use the MIGX-snippet migxLoopCollection to create the options for a select form field.

You would put lines like these into your FormIt code

<select name="my_select" id="my_select">
	[[!migxLoopCollection?&packageName=`mypackage` &classname=`MyClass`&tpl=`tplOption`&selected=`[[!+fi.my_select]]`]]
</select>

and then create the chunk tplOption with

<option value="[[+id]]" [[+id:eq=`[[+property.selected]]`:then=` selected="selected"`]]>[[+my_column_name]]</option>

Change all the names according to your schema.
You can also filter and sort the values with migxLoopCollection.

For a quick introduction to MIGXdb you can watch this youtube video.

Thanks halftrainedharry. I shall look into it and let you know.

I have downloaded and installed MIGXdb but it is not working as per the video. It is not creating a package folder easily nor saves the schema correctly and does not parse the schema when I eventually get one in. Sometimes I have to delete the cache before I can get MIGX to work.

Am I missing something in the installation and setup?

I am using Modx version 2.7.3

  1. what happens, when you try to add a package folder?
  2. what happens, when you try to save the schema?

When I click on create package there is no success message and a package folder does not appear in the core/components folder

could be a file permission issue. Do you see any answer in the console network-tab?

How do I find the console network-tab?

In your ‘browser developer console’ there is tab called ‘network’.
An ajax-call to connector.php should be generated if you click the ‘Create Package’-button.

The developer tools can usually be accessed with F12 or Cmd+Opt+J depending on your browser and operating system.

The network-tab shows

thats the Console tab, what shows the Network tab?

Is this what you want?

If you click the red line a new window should appear on the right with a tab called ‘Response’.
What is the content of this tab?

The response is

response

ok, that doesn’t say much. Any errors in the logs?
what PHP - Version?

PHP version 7.3
Error log is

ok,
first, set the system-setting log_deprecated to no
and debug to 0

and see what you get then in the error-log

Thanks Bruno17
I shall look into it later and let you know.
Thanks for your help so far

Bruno17, I have made the system changes and there are no additional errors in the error log. However, MIGX is still not creating a package. Is it an issue of permissions?

did you clean the error log before looking again? what are the errors after you clean the error log.
maybe you should also look into the server error log, if you have access