How to Save Elementor Form Data to MySQL Database
-
I work with WAMP and phpmyadmin on localhost. I found code, which allows me to save 3 rows – name, email and message in MYSQL database, content table.
add_action( 'elementor_pro/forms/new_record', function( $record, $ajax_handler ) { $raw_fields = $record->get( 'fields' ); $fields = []; foreach ( $raw_fields as $id => $field ) { $fields[ $id ] = $field['value']; } global $wpdb; $output['success'] = $wpdb->insert('content', array( 'name' => $fields['name'], 'email' => $fields['email'], 'message' => $fields['message'])); $ajax_handler->add_response_data( true, $output ); }, 10, 2);
In the above simple form row name has label name and ID name, email and message – the same.
But my custom form has much more rows such as as: age, gender, date of disappearance, height, weight, eye color and more… Each of them has different labels and Id. For example: row FULL NAME has label Name and ID name; row GENDER has label Gender and ID field_f5717c6;
My question what I will use to enter into the form above labels and/or ID fields, and does it matter, if I use capital letters or not. How in the same form I can save to MySQL database 4 image files after submitting the form. Do I have to create a separate data table or in the same one?
Regards, Sam.
- The topic ‘How to Save Elementor Form Data to MySQL Database’ is closed to new replies.