different answer form

4.66K viewsGeneralcustom field
0

hi, i’m trying to create a different answer form using custom fields but i can’t, so i need a little help.
First of all i don’t want to use the default answer form and i want to replace it with a new one. The new answer form i want to contain three custom fields

  1. Textarea custom field
  2. Upload image custom field
  3. Captcha (if is possible)

When a user submit an answer the contents of the custom fields must be stored into a database.
When a user reading the question and the answers the contents must be available.
I know that there is a help file about custom fields ( https://anspress.io/resources/faq/anspress-form-and-validation-api/ ) but i can’t working with this….so i ‘ll be happy if you can give me the code and the way to put this code to the correct file.
Thanks for the support.

Answered question
0

hi, any help?
i’m trying this code (for Upload image custom field)
)
I add the code to the end of anspress/includes/functions.php file.

/**
 * Add custom fields and save to AnsPress answer form.
 *
 * @param array $form Form arguments.
 * @return void
 */
 function my_custom_answer_field( $form ) {
     // Upload field.
  $form['fields']['ss'] = array(
    'label'       => __( 'screenshot' ),
    'desc'        => __( 'Upload screenshots' ),
    'type'        => 'upload',
    'sanitize' => '', // Comma separated list of sanitization filters
'validate' => '', // Comma separated list of validation methods
    'upload_args' => array(
      'multiple'  => false, // Only allow single image upload.
    ),
  );
  return $form;
}
add_filter( 'ap_answer_form_fields', 'my_custom_answer_field' );
 function hooks_save_meta_value($post_id,$post)
{
$form = anspress()->get_form( 'form_answer' );
// Get all sanitized values.
$values = $form->get_values();
if ( ! add_post_meta( $post_id, 'xyz', $values['ss']['value'], true ) ) {
update_post_meta( $post_id, 'xyz', $values['ss']['value'] );
}
}
add_action( 'ap_after_new_answer', 'hooks_save_meta_value' );


but something is wrong and no working.
Can you help me about this?
thanks for the support

Edited comment

It will not work like that. Custom form for answer is not supported by AnsPress yet.

i’m trying the same code (replace the word “answer” with the name “question” on the code) but it’s not working!!!

basically, i’m looking for the correct code about the answer form as i describe in my first question. Is it possible or not?

You are viewing 1 out of 1 answers, click here to view all answers.