-
-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comment system #3472
Comments
I have seen a couple pop up over time on the extensions marketplace. That said… I've never tried this, but BoltForms can save to a contenttype, and you can specify hidden fields… So technically you could implement it already with Bolt + BoltForms. Just food for thought/conversation. |
I will try that. Why do I have to use hidden fields? |
I must have been attempting to imitate Captain Obtuse 😀 The thought was if you had some meta, such as the record number and the contenttype of the page you were on, you could use those. Then on loading of a page, you can just do a |
I need some more info about getcontent in general and using it to display content for a specific entry. It is not in the documentation and I haven't tried something like this before. And when I use the following code:
Are all fields that I use in the comment form stored in the database for that specific entry? |
I've read the info about setting content before. Now I'm confused. GawainLynch mentioned the 'getcontent' tag (instead of the 'set content' tag) and about that there is no information in the documentation. |
Sorry, my bad… you want |
Thanks! I know I can use 'setcontent' to display specific content from records in a specific content type. Is that why I have to use the entry id as a hidden field in the comment form to display comments for only the entry with that id later on? The Bolt Forms extension contains database settings. When I uncomment these, is all the info of the comment form then stored in the given contenttype? |
Possibly. Was thinking aloud, mostly, but that seems to be something I think you'll need.
Each form will have a section like this: # database:
# contenttype: mycontenttype # Contenttype to create
# table: bolt_secret_table # Specific database table to write to You would only need to do this: database:
contenttype: mycontenttype …and then make sure |
And that contenttype with fields have to be in the main config file of Bolt also? |
Yep, in comments:
name: Comments
singular_name: Comment
fields:
title:
type: text
slug:
type: slug
uses: title
record_type:
type: text
record_id:
type: text
author:
type: text
comment:
type: textarea
default_status: published
searchable: false
viewless: true NOTE: Above is untested and straight off the top of my head 😁 |
I think I'm almost there... The extension config file doesn't accept In the extension config file this is what I have for that part: record_id:
type: text
value: {{ record.id }} |
We might be on different pages here… but the example I gave was for |
Yes, I know. But to add the record id to 'record_id' (comments contenttype) after the comment is send, I need to add the record id to the form first. Just like how the comment text itself is saved to the database (via a field in both config files). Or am I thinking wrong? |
Ah, cool. OK, well first thing to know is that YAML doesn't understand Twig, i.e. What you need to do a custom {{ form_widget(form.record_id, { 'value' : record.id }) }} |
Or add a input field with a pre-set value (record id) manually? Sorry... I understand what the code you provided does, but it goes beyond my knowledge to implement it. I also discovered something else. In the source code, an input field has a name like 'comments[name]' or 'comments[message]'. In this code 'comments' is the name of the form and '[...]' is the name of the field. The names in the config file for the contenttype are different. Should these also be 'comments[...]' instead of only the field name (like they are defined in the extension config file? Have I already said that I'm really thankful for your help? Thanks! |
OK, I shall have a go here at mocking up an example based on the current The relevant bit in fields:
record_type:
type: hidden
record_id:
type: hidden {% form_theme form 'boltforms_custom.twig' %}
{% block boltforms_css %}
<link href="{{ app.paths.extensions }}vendor/bolt/boltforms/css/boltforms.css" rel="stylesheet" type="text/css" />
{% endblock boltforms_css %}
<div class="boltform">
{% if error and app.request.get(formname) %}
<p class="boltform-error">{{ error }}</p>
{% endif %}
{% if message and app.request.get(formname) %}
<p class="boltform-message">{{ message }}</p>
{% endif %}
{% if not sent %}
{{ html_pre }}
{% if recaptcha.theme|default('clean') %}
<script>
var RecaptchaOptions = {
theme : '{{ recaptcha.theme }}'
};
</script>
{% endif %}
{{ form_start(form, {'attr': {'name': formname}}) }}
{{ form_errors(form) }}
{% for key, value in fields %}
{% if value.config.name != 'submit' and value.config.name != 'record_type' and value.config.name != 'record_id' %}
<div class="boltforms-row{% if form[key].vars.attr.class is defined %} boltforms-{{ form[key].vars.attr.class }}-row{% endif %}">
{{ form_label(form[key]) }}
{{ form_errors(form[key]) }}
{{ form_widget(form[key]) }}
</div>
{% elseif value.config.name == 'record_type' %}
{{ form_widget(form.record_type, { 'value' : record.contenttype }) }}
{% elseif value.config.name == 'record_id' %}
{{ form_widget(form.record_id, { 'value' : record.id }) }}
{% endif %}
{% endfor %}
{% if recaptcha.enabled %}
{% if not recaptcha.valid %}
<ul class="boltform-error">
<li class="boltform-errors">{{ recaptcha.error_message }}</li>
</ul>
{% endif %}
<div class="boltform-row">
<label for="form_message" class="required">{{ recaptcha.label }}</label>
<script src="https://www.google.com/recaptcha/api.js?hl={{ htmllang() }}" async defer></script>
<div class="g-recaptcha" data-sitekey="{{ recaptcha.public_key }}"></div>
</div>
{% endif %}
<br>
<div class="boltforms-row{% if form.submit.vars.attr.class is defined %} boltforms-{{ form.submit.vars.attr.class }}-row{% endif %}">
{{ form_row(form.submit) }}
</div>
{{ form_end(form) }}
{% else %}
{{ html_post }}
{% endif %}
</div> DISCLAIMER: again done mostly off the top of my head 😁 |
Thanks again! Is the contenttype as a hidden field relevant? With a template tag I can make the form visible on only entry pages. And I can sort based on the record id. I will try to make it work and let you know when it's implemented. I'm really thankful for your help and won't bother you again with this. I'm just not such a code expert as you guys. Everyday it's getting better. |
Ah, zero stress, you're very welcome!
That's the extension config this time, it just means that they won't show on the actual form as displayed to the user. The matching fields in the Contenttype are just
Cool, it's always great to see what people come up with from your work… I am sure @bobdenotter gets a kick out of it every day, just seeing how Bolt has grown and is being used 👍 |
That is correct. I know that a hidden field won't show on the actual form. I was only wondering why the contenttype hidden input field is relevant for the comment form to function when I can publish comments and sort with the comment id. Btw: it returns 'Array'... It is implemented and when I publish a comment, it is stored in the database. So that is looking good! Does Bolt assign an independent id to it that has nothing to do with the id that is set with the form and that is used to sort comments? |
The idea of saving the comments record with the page record contenttype and ID is for doing look ups, that way you can in the template get the record Conenttype ("pages" in this example) and the record's ID (42 in this example) and get: {% setcontent comments = "pages/42" %}
{% for comment in comments %}
{# Display comment data here #}
{% endfor %} |
I understand... I only don't see the use of it, because the contenttype is given in the extension config file (database settings) and also in Bolts config file (as the actual contenttype). When the hidden field for the contenttype isn't present, the comment is still stored in the database and I can use setcontent to display entries from the comments contenttype. |
What you are trying to store in the comment record is the Contenttype and ID of the site page it relates to, or in another way of putting it, the record it is "commenting on". |
I'm sorry... I'm confused now. I know the basic principals of 'setcontent' and 'contenttype'. But the contenttype tag puts out 'array' instead of the actual contenttype. That aside, I'm thinking this way:
In the example you gave me record 42 from 'pages' is set. And then comes some code to display comments. But contenttype 'pages' doesn't contain fields like contenttype 'comments' does. So how can I display comments when the comments contenttype isn't fetched? When I remove the hidden contenttype field and someone leaves a comment, the comment is stored in the database with only the id of the record the comment is for. My thought was to add the following code to the record template:
I haven't tested it yet. I think this code only sets content from the contenttype 'comments' that have the record_id from the record they are on. |
It looks like this also doesn't work. When I add the record id manually, it does. Is is not possible to do this below?
|
What about: {% setcontent comments = 'comments' where { record_id: record.id } %} |
Nope... that doesn't set the id of the page the comments are on. Just to clear things up: I hope you didn't get the feeling that I was pedantic with my last post yesterday. I know much less then you about this and I admire the fact that you can produce such code like writing a text. I just try to understand the things I'm doing. UPDATE: It does work! A typo messed things up. Now I have a comment form that stores comments in the database and these comments are displayed below the record with a corresponding record id. |
Hehe… No, your input is never taken badly by me. My work on Bolt is for fun, and as such I do the best I can to not let any of it stress me… and keep it fun 😁 With respect to what we're trying to do here, if there is nothing coming back in that OK, so just stepping though the obvious places that Gawain would make mistakes — believe me, it's a well developed skill of mine — the places/things to look/check are:
|
It was a typo... I did record_id and it should be record.id... Now I have a comment form that stores comments in the database and these comments are displayed below the record with a corresponding record id. |
Closing in "clean up mode" |
I miss the build in comment system of PivotX. Why is this not a part of Bolt anymore? Not everyone likes external services like Disqus. I think this service has an over complete form and I just need a simple comment system that I can host myself. Users don't have to log in, they only have to provide their name, email address and a comment.
The text was updated successfully, but these errors were encountered: