• Resolved jester48

    (@jester48)


    I have created a custom comment form by rewriting the fields in a function

    Q:
    How do I make my custom fields required when submitted?

    Current custom fields are not being saved, what should i be looking at/changing?

    would it be better to create my own comments form and submission pages?
    how do i do that?

    thanks

    Jester

Viewing 7 replies - 1 through 7 (of 7 total)
  • Start here:
    http://codex.wordpress.org/Function_Reference/comment_form

    Make sure you’re using the proper method for customizing the comment reply form, and then see what questions you still have. We’ll be happy to try to help!

    Thread Starter jester48

    (@jester48)

    been through that but it’s not helping

    my theme was using the comment-template.php file and now it is using the wp-content\theme-compat\comments.php and I have no idea why, i can customize the fields but can’t get the form to switch back to using the right file

    my theme was using the comment-template.php file and now it is using the wp-content\theme-compat\comments.php and I have no idea why

    1) Is your Theme calling <?php comments_template(); ?>

    2) Does your Theme include comments.php?

    Thread Starter jester48

    (@jester48)

    that was it, someone had changed the parent theme file
    (shakes head – always looking for the big mistakes never the obvious)
    thanks

    @jester48,

    Would you mind sharing what you did to create a custom comment form?

    I am wanting to change my comment form. I am building a WP site to be used for a Policies and Procedures Manual on our corporate network. Viewers will only be subscribed users, and I am only wanting to give them an option of a checkbox stating that they have reviewed the policy. I have no need for the website or comment fields. Suggestions?

    Thread Starter jester48

    (@jester48)

    @dalincster

    the wp functionality allows you to create custom fields

    to create custom input fields I added this to my theme functions.php

    //custom comment fields
    // the po is related to my theme name
    function po_custom_comment_fields($fields)
    {
      global $post;
    // i didn't want the default fields so i remove them here
    	$fields['author'] = '';
    	$fields['email'] = '';
        $fields['url'] = '';
    // begin custom fields
        $fields['firstname'] = '' . '<label for="firstname">' . __( 'First Name' ) . '</label> ' .
          '<input id="firstname" name="firstname" type="text" value="' . esc_attr( $commenter['firstname'] ) . '" size="30" /><span class="required">*</span>';
    	$fields['lastname'] = '' . '<label for="lastname">' . __( 'Last Name' ) . '</label> ' .
          '<input id="lastname" name="lastname" type="text" value="' . esc_attr( $commenter['lastname'] ) . '" size="30" /><span class="required">*</span>';
    
    	$fields['location'] = '' . '<label for="location">' . __( 'Location' ) . '</label> ' .
          '<input id="location" name="location" type="text" value="' . esc_attr( $commenter['location'] ) . '" size="30" /><span class="required">*</span>';
    
    // add all the fields created above in to a new array and return the new array
        $fields = array( $fields['author'], $fields['email'], $fields['url'], $fields['firstname'], $fields['lastname'], $fields['location'] );
      return $fields;
    }
    
    add_filter( 'comment_form_default_fields', 'po_custom_comment_fields' );

    to save the fields

    add_action ('comment_post', 'add_meta_settings', 1);
    function add_meta_settings($comment_id) {
    	add_comment_meta($comment_id, 'firstname', $_POST['firstname'], true);
    	add_comment_meta($comment_id, 'lastname', $_POST['lastname'], true);
    	add_comment_meta($comment_id, 'location', $_POST['location'], true);
    }

    there may be a better way, Chip Bennett, above, would probably be more qualified to give input on that, but this was what I did and it works for what i needed to do.
    I might not be the best source for this, this is my first WP project in about 3 years

    @jester

    Thanks for the help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom Comment Form’ is closed to new replies.