Forums

Auto fetch article title to a form field value

arvendal 10 May, 2019
Hello,
I have a form for ordering the latest issue of a magazine and I wonder if it is possible to put a field into the form that auto fetches the title of the latest article in a specific category in Joomla? For example if the latest article has the title "[The Magazine Name] # 1 -2019 [Theme Name]" could be auto displayed in the form both for the buyer and in the form message delivered to the publisher?
Hope you understand my purpose.

Best regards
healyhatman 10 May, 2019
Yes, easily. Just get the #__content first matching order by created data descending, where catid = the category ID you want.
arvendal 11 May, 2019
Thanks!
May I ask you to describe a little more how this is done, this is a bit beyond my knowledge so far. What kind of field do I need to configurate and what would be the code?

Best regards

Ps. I downloaded your shortcodes. Interesting, it opens a window to things I have not done with Chronoforms yet, but I am not experienced enough to be able to work it out without further clues.
healyhatman 11 May, 2019
Read data. Read the table #_content.

In the where conditions put catid = xxx replacing xxx with the ID of the specific category you want

In Order Fields put "created" set to descending

Set the action to Return First Matching

Then use {var:read_data#.model.title} where you want the title displayed, replacing # with the number in the black label of your read data action.
arvendal 11 May, 2019
Thanks!

I recieved an error 1054 - Unknown column 'Data11.created' in 'order clause' when I created an action with these settings.
This is what my settings look like:


So I must have missed something.

And do I put the string {var:read_data11.model.title} into a HTML container in the Views tab?

Sorry for all your troubles, but I am not accustomed to these kind of applications in Chronoforms.

Best regards
healyhatman 11 May, 2019
is created in your fields to retrieve as well?
arvendal 11 May, 2019
This is where I am unsure: the combination of fields in design view and the actions. I put this HTML container in the design view:


But even if I remove this part, I still get the error message as shown above.

Best rgds
arvendal 11 May, 2019
I think the problem may occur in the "Fields to retrieve". In the example above I wrote "title" and I got the error message. The page loads OK if I remove this and leave the field empty.

My inability to solve this depends on my lack of knowledge in how to communicate with the database.

- What must I write in "Fields to retrieve" to get the title from the article?
- What kind of field do I need in the form design to present this information? And what is the syntax in this field?

Best regards
healyhatman 11 May, 2019
If you only put title in the fields to retrieve then it can't order by created because you haven't retrieved it. If you leave it blank it gets all fields
arvendal 12 May, 2019
Thanks for your answer, but I can't get it to work.
I can display the shortcodes I downloaded from your site in different kinds of form fields, but this shortcode {var:read_data11.model.title} can't be displayed in the same fields.

I don't know what I do wrong. I remove everything from the "Fields to retrieve" in the read data section in actions, so it is empty now. The table #_content is there, I use "first matching record" and the catid is set to the proper one. And I have put a HTML field in the form design where different shortcodes work, but not the one mentioned above.

The debugger doesn't display anything at all (the red arrow shows where the "var:read_data" would appear):


Probably I am missing something very basic. I fear I lack the knowledge to solve this.

I so grateful for all help I recieved.

Best rgds
healyhatman 12 May, 2019
That's actually not where it would show up in the debugger, it would be a lot lower. Make sure the read data is before the debugger.
arvendal 12 May, 2019
I think I am getting closer!
Now the debugger displays the retrieving of the db record in a correct way:



And the ID=10626 is correct.

But I have no display in my form when using this code in a checkbox field:


("Jag vill köpa" means "I want to buy")

It displays at the form like this:



What do I do wrong?

Best regards
healyhatman 12 May, 2019
well you can't literally just write "model" unless that's the name of your read data model
arvendal 12 May, 2019
Brilliant! I knew it had to be some simple thing I have missunderstood.

It works like a charm! Thank you, Healyhatman, for your patience!

This will save me so much time in the future when new magazines are issued.

Best regards
This topic is locked and no more replies can be posted.