Jump to content

Comment form with custom HTML


Kai2000
 Share

Recommended Posts

Hello

I want to migrate a very old Blog to a new system and testing Processwire currently. I have a rather "complex" comment form and want to keep the design, but can't find a solution to use my own markup for the form.

Only question I found is this one: https://processwire.com/talk/topic/8194-own-markup-for-comment-form/

It says, it is in the docs, but actually there is just this:

Quote

You can likewise do the same for the comment form. But I don't want to get too far into this level yet since this is supposed to be a quick guide.

I couldn't figure out, how to foreach the form fields.

Anybody has done it?

Link to comment
Share on other sites

Hi @Kai2000, I think you can find this guide very helpful:

https://processwire.com/docs/modules/guides/comments/

in particular in the section "Generating your own output":

foreach($page->comments as $comment) {
    if($comment->status < 1) continue; // skip unapproved or spam comments
    $cite = htmlentities($comment->cite); // make sure output is entity encoded
    $text = htmlentities($comment->text);
    $date = date('m/d/y g:ia', $comment->created); // format the date
    echo "<p><strong>Posted by $cite on $date</strong><br />$text</p>";
}

EDIT: I realized you were looking to the comment FORM markup, not the comments markup. ?

As a first step, if you use Uikt 3 Site/Block Template you can look at file _uikit.php in site/templates directory, and look at function ukCommentForm(). This function calls $comments->renderForm($options) with a set of $options. You can find details about these options in wire/modules/FieldtypeComments file CommentForm.php. What you can do is to see if you can shape out your form using these options.

In case providing $options is not sufficient you can consider to modify CommentForm.php to setup your custom form. However do not modify the original one, you can duplicate FieldtypeComments module under site/modules. Suggest to refer to this tutorials about duplicating the module and modify the comment form:

 

Edited by Edison
Link to comment
Share on other sites

@Kai2000 Hello Kai and welcome to the PW Forum. I remember having a battle with my comments list and comments form the first time I needed to implement those and I was able to manage it with ratings, custom styling and inline replies. Here is the topic for you in case you haven't found it. With your own custom markup for the comments list and/or comment form I would suggest as the easiest way to copy the FieldType Comments module from /wire/modules to /site/modules and apply all the custom styling to this version. As I see, @Edison beat me on this and he also helped me to show comments based on the user/site language. Just follow the steps to select your new module copy from the admin (listed in one of the links of Edison and you would have your markup in no time. It seemed a bit confusing for me at the beginning, but you will get used to it and be able to manage any complexity of your comments. Should you have some difficulties understanding the code or adding a copy of the module, feel free to reach back to me and I will be glad to help ?
 

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...