// ตัวอย่างโค้ด Ninja Form Line Notify
add_action( 'ninja_forms_after_submission', 'my_ninja_forms_after_submission' );
function my_ninja_forms_after_submission( $form_data ){
// Ninja Form data
$form_id = $form_data['form_id'];
$form_title = $form_data['settings']['title'];
$text = $form_title."\n"."\n";
foreach ($form_data['fields'] as $key => $field) {
if(!empty($field['value'])){
$text .= $field['label']." : ".$field['value']."\n";
}
}
// LINE Notify
wpdt_line_notify_text($text);
}
// ตัวอย่างโค้ด Contact 7 Form Line Notify
add_action( 'wpcf7_mail_sent', 'your_wpcf7_function' );
function your_wpcf7_function( $contact_form ) {
$id = $contact_form->id;
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
$posted_data = array();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
$text = "#".$id." - ".$title."\n"."\n";
$text .="You Name: ".$posted_data['your-name']."\n";
$text .="Your Email: ".$posted_data['your-email']."\n";
$text .="Subject: ".$posted_data['your-subject']."\n";
$text .="Your Message: "."\n".$posted_data['your-message']."\n";
// LINE Notify
wpdt_line_notify_text($text);
}
// ตัวอย่างโค้ด Elementor Pro Forms Line Notify
// A elementor_pro/forms/new_record custom WebHook
add_action( 'elementor_pro/forms/new_record','wpdt_elementor_pro_forms_line_notify', 10, 2 );
function wpdt_elementor_pro_forms_line_notify($record, $handler){
// Elementor Pro Form data
$form_name = $record->get_form_settings( 'form_name' );
$raw_fields = $record->get( 'fields' );
$text = $form_name."\n"."\n";
foreach ( $raw_fields as $id => $field ) {
if(!empty($field['value'])){
$text .= $field['title']." : ".$field['value']."\n";
}
}
// LINE Notify
wpdt_line_notify_text($text);
}
/**
* This will fire at the very end of a (successful) form entry.
*
* @link https://wpforms.com/developers/wpforms_process_complete/
*
* @param array $fields Sanitized entry field values/properties.
* @param array $entry Original $_POST global.
* @param array $form_data Form data and settings.
* @param int $entry_id Entry ID. Will return 0 if entry storage is disabled or using WPForms Lite.
*/
function wpdt_wpf_process_complete( $fields, $entry, $form_data, $entry_id ) {
// wpForm data
$form_id = $form_data['id'];
$form_title = $form_data['settings']['form_title'];
$text = $form_title."\n"."\n";
foreach ($fields as $key => $field) {
if(!empty($field['value'])){
$text .= $field['name']." : ".$field['value']."\n";
}
}
// LINE Notify
wpdt_line_notify_text($text);
}
add_action( 'wpforms_process_complete', 'wpdt_wpf_process_complete', 10, 4 );
// ตัวอย่างโค้ด User Login Line Notify
add_action('wp_login', 'wpdt_user_login_line_notify', 10, 2);
function wpdt_user_login_line_notify( $user_login, $user ) {
$text = "User Loign"."\n\n";
$text .="User Name: ".$user->user_login."\n";
$text .="User Email: ".$user->user_email."\n";
$text .="Display Name: ".$user->display_name."\n";
$text .="Date Time: ".date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) )."\n";
// LINE Notify
wpdt_line_notify_text($text);
}
// ตัวอย่างโค้ด User Logout Line Notify
// define the clear_auth_cookie callback
add_action( 'clear_auth_cookie', 'wpdt_user_logout_line_notify', 10, 0 );
function wpdt_user_logout_line_notify( ) {
$user = wp_get_current_user();
if($user->user_login){
$text = "User Logout"."\n\n";
$text .="User Name: ".$user->user_login."\n";
$text .="User Email: ".$user->user_email."\n";
$text .="Display Name: ".$user->display_name."\n";
$text .="Date Time: ".date( 'Y-m-d H:i:s', current_time( 'timestamp', 0 ) )."\n";
// LINE Notify
wpdt_line_notify_text($text);
}
};
add_action('fluentform_submission_inserted', 'your_custom_after_submission_function', 20, 3);
function your_custom_after_submission_function($entryId, $formData, $form) {
if ($form->id == 1) {
$form_title = $form->title;
$form_fields = json_decode($form->form_fields);
$text = $form_title.
"\n".
"\n";
foreach($form_fields->fields as $key => $field) {
if (!empty($formData[$field->attributes->name])) {
switch ($field->element) {
case 'input_name':
$text. = $field->settings->admin_field_label.
" : ".$formData[$field->attributes->name]['first_name'].
" ".$formData[$field->attributes->name]['last_name'].
"\n";
break;
case 'address':
$text. = $field->settings->label.
" : ".$formData[$field->attributes->name]['address_line_1'].
" ".$formData[$field->attributes->name]['address_line_2'].
" ".$formData[$field->attributes->name]['city'].
" ".$formData[$field->attributes->name]['state'].
" ".$formData[$field->attributes->name]['zip'].
"\n";
break;
default:
$value = $formData[$field->attributes->name];
if (is_array($value)) {
$value = implode(",", $value);
}
$text. = $field->settings->label.
" : ".$value.
"\n";
break;
}
}
}
// LINE Notify
wpdt_line_notify_text($text);
return;
}
}