'success',
'message' => __('Form imported successfully', "ajaxy-forms"),
];
} catch (\Exception $e) {
$message = [
'type' => 'error',
'message' => sprintf(__('Failed to import the form. Please make sure the JSON is valid: %s', "ajaxy-forms"), $e->getMessage()),
];
}
if ($message) : ?>
create a new form. Do not forget to save your changes!', "ajaxy-forms"),
esc_url(
admin_url('admin.php?page=ajaxy-form&action=add')
)
), ['a' => ['href' => '']]);
?>
'error',
'message' => __('You are not allowed to edit form actions.', "ajaxy-forms"),
], 403);
return;
}
$post_vars = array_map('stripslashes_deep', $_POST);
$name = $post_vars['name'] ?? '';
if (!$name) {
wp_send_json([
'status' => 'error',
'message' => __('Invalid action name', "ajaxy-forms"),
], 200);
return;
}
$form = Data::get_form($_GET['form_id'] ?? '');
if (!$form) {
wp_send_json([
'status' => 'error',
'message' => __('Form doesn\'t exist or haven\'t been saved yet', "ajaxy-forms"),
], 200);
return;
}
if (!wp_verify_nonce($post_vars['_wpnonce'], 'ajaxy_forms_action_' . $name)) {
wp_send_json([
'status' => 'error',
'message' => __('Nonce verification failed, Please try again.', "ajaxy-forms"),
], 200);
return;
}
$values = $post_vars['form_action'] ?? [];
// The form never receives the saved credentials, so an empty one
// means it was left alone rather than cleared.
$existing = [];
try {
$existing = (array)\json_decode($form['actions'] ?? '', true);
} catch (\Throwable $e) {
$existing = [];
}
$previous = $existing[$name] ?? [];
foreach (\Ajaxy\Forms\Inc\Actions::getInstance()->get_properties($name) as $property) {
if (empty($property['secret'])) {
continue;
}
$key = $property['name'] ?? '';
if ($key && empty($values[$key]) && !empty($previous[$key])) {
$values[$key] = $previous[$key];
}
}
$saved = Data::update_form_action($form['id'], $name, $values);
if ($saved === false) {
wp_send_json([
'status' => 'error',
'message' => __('Failed to save the action', "ajaxy-forms")
], 200);
return;
}
$response = [
'status' => 'success',
'message' => \sprintf(__('Action "%s" is saved!', "ajaxy-forms"), $name),
];
wp_send_json($response);
}
}