save custom field in form question

8.91K viewsIssuesbug
0

Cretae new custom field:

function custom_form_fields( $form ) {
// Upload field.
$form[’fields’][’budget’] = array(
‘label’ => __( ‘Budget’ ),
‘desc’ => __( ‘Tu presupuesto máximo..’ ),
‘subtype’ => ‘text’,
);
return $form;
}
add_filter( ‘ap_question_form_fields’, ‘custom_form_fields’ );

Save field:

function question_mysave( $post_id, $post ) {
global $validate;
if ( empty( $validate ) ) {
return;
}
$fields = $validate->get_sanitized_fields();

update_post_meta( $post_id, ‘budget’, $fields[’budget’] );
}

add_action( ‘ap_processed_new_question’, array( $this, ‘question_mysave’ ), 0, 2 );
add_action( ‘ap_processed_update_question’, array( $this, ‘question_mysave’ ), 0, 2 );

 

Don’t save the custom field. ¿why?

Answered question
0

I have posted an answer here: https://anspress.io/questions/question/custom-field-not-saving/answer/29376/

Answered question
0

Y don’t find an example in this page.

I only view this example
How to add a PDF upload field in AnsPress question form?
 

But don`t work.

 

I try:

 

function my_save_pdf_uploads( $post_id ) {
$field = $form->find(‘budget’);

update_post_meta( $post_id, ‘budget’, $field );
}
}
add_action( ‘ap_processed_new_question’, ‘my_save_pdf_uploads’ );

add_action( ‘ap_processed_update_question’, ‘my_save_pdf_uploads’ );

0

Hello,

You are not saving it correctly. Please read our FAQ AnsPress form and validation API at the bottom there is an example of how to save form data.