Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion classes/controllers/FrmOnboardingWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,14 @@ public static function ajax_setup_email_step() {
check_ajax_referer( 'frm_ajax', 'nonce' );

// Get posted data.
$default_email = FrmAppHelper::get_post_param( 'default_email', '', 'sanitize_text_field' );
$from_email = FrmAppHelper::get_post_param( 'from_email', '', 'sanitize_email' );
$default_email = FrmAppHelper::get_post_param( 'default_email', '', 'sanitize_email' );
$allows_tracking = FrmAppHelper::get_post_param( 'allows_tracking', '', 'rest_sanitize_boolean' );
$summary_emails = FrmAppHelper::get_post_param( 'summary_emails', '', 'rest_sanitize_boolean' );

// Update Settings.
$frm_settings = FrmAppHelper::get_settings();
$frm_settings->update_setting( 'from_email', $from_email, 'sanitize_text_field' );
$frm_settings->update_setting( 'default_email', $default_email, 'sanitize_text_field' );
$frm_settings->update_setting( 'tracking', $allows_tracking, 'rest_sanitize_boolean' );
$frm_settings->update_setting( 'summary_emails', $summary_emails, 'rest_sanitize_boolean' );
Expand Down
37 changes: 37 additions & 0 deletions classes/helpers/FrmAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4331,4 +4331,41 @@ public static function tooltip_icon( $tooltip_text, $atts = array() ) {
</span>
<?php
}

/**
* Prints errors for settings in onboarding wizard or template settings.
*
* @since x.x
*
* @param array $args Args.
*
* @return void
*/
public static function print_setting_error( $args ) {
$args = wp_parse_args(
$args,
array(
'id' => '',
'errors' => array(),
'class' => '',
)
);

$args['class'] .= ' frm-validation-error frm-mt-xs frm_hidden';
?>
<span id="<?php echo esc_attr( $args['id'] ); ?>" class="<?php echo esc_attr( $args['class'] ); ?>">
<?php
if ( is_array( $args['errors'] ) ) {
foreach ( $args['errors'] as $key => $msg ) {
?>
<span frm-error="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $msg ); ?></span>
<?php
}
} else {
echo '<span>' . esc_html( $args['errors'] ) . '</span>';
}
?>
</span>
<?php
}
}
15 changes: 15 additions & 0 deletions classes/helpers/FrmEmailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,19 @@ public static function get_user_id_field_for_form( $form_id ) {
public static function remove_mandrill_br() {
return false;
}

/**
* Gets default from email address in header for emails.
*
* @since x.x
*
* @return string
*/
public static function get_default_from_email() {
$settings = FrmAppHelper::get_settings();
if ( $settings->from_email && is_email( $settings->from_email ) ) {
return $settings->from_email;
}
return get_option( 'admin_email' );
}
}
2 changes: 1 addition & 1 deletion classes/models/FrmEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function prepare_additional_recipients( $recipients, $user_id_args ) {
*/
private function set_from( $user_id_args ) {
if ( empty( $this->settings['from'] ) ) {
$from = get_option( 'admin_email' );
$from = FrmEmailHelper::get_default_from_email();
} else {
$from = $this->prepare_email_setting( $this->settings['from'], $user_id_args );
}
Expand Down
2 changes: 1 addition & 1 deletion classes/models/FrmEmailSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function get_recipients() {
protected function get_headers() {
return array(
'Content-Type: ' . ( $this->is_html ? 'text/html; charset=UTF-8' : 'text/plain' ),
'From: ' . get_bloginfo( 'name' ) . ' <' . get_bloginfo( 'admin_email' ) . '>',
'From: ' . get_bloginfo( 'name' ) . ' <' . FrmEmailHelper::get_default_from_email() . '>',
);
}

Expand Down
2 changes: 2 additions & 0 deletions classes/models/FrmSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class FrmSettings {
public $summary_emails_recipients;

public $default_email;
public $from_email;
Comment thread
shervElmi marked this conversation as resolved.
public $currency;

/**
Expand Down Expand Up @@ -403,6 +404,7 @@ private function update_settings( $params ) {
$this->load_style = $params['frm_load_style'];
$this->custom_css = $params['frm_custom_css'];
$this->default_email = $params['frm_default_email'];
$this->from_email = $params['frm_from_email'];
$this->currency = $params['frm_currency'];

$checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'no_ips', 'custom_header_ip', 'tracking', 'admin_bar', 'summary_emails' );
Expand Down
18 changes: 13 additions & 5 deletions classes/views/form-templates/modals/code-from-email-modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@
<div class="frm-form-templates-modal-fieldset frm_form_field">
<input id="frm_code_from_email" type="text" placeholder="<?php esc_attr_e( 'Code from email', 'formidable' ); ?>" />

<span id="frm_code_from_email_error" class="frm-validation-error frm-justify-center frm-items-center frm-mt-xs frm_hidden">
<span frm-error="custom"></span>
<span frm-error="invalid"><?php esc_html_e( 'Verification code is wrong', 'formidable' ); ?></span>
<span frm-error="empty"><?php esc_html_e( 'Verification code is empty', 'formidable' ); ?></span>
</span>
<?php
FrmAppHelper::print_setting_error(
array(
'id' => 'frm_code_from_email_error',
'errors' => array(
'custom' => '',
'invalid' => __( 'Verification code is wrong', 'formidable' ),
'empty' => __( 'Verification code is empty', 'formidable' ),
),
'class' => 'frm-justify-center frm-items-center',
)
);
?>
</div>

<div id="frm_code_from_email_options" class="frm-justify-center frm-items-center frm_hidden">
Expand Down
16 changes: 12 additions & 4 deletions classes/views/form-templates/modals/leave-email-modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@
<input id="frm_leave_email" type="email" placeholder="<?php esc_attr_e( 'Enter your email', 'formidable' ); ?>" value="<?php echo esc_attr( $user->user_email ); ?>" />
</span>

<span id="frm_leave_email_error" class="frm-validation-error frm-justify-center frm-items-center frm-mt-xs frm_hidden">
<span frm-error="invalid"><?php esc_html_e( 'Email is invalid', 'formidable' ); ?></span>
<span frm-error="empty"><?php esc_html_e( 'Email is empty', 'formidable' ); ?></span>
</span>
<?php
FrmAppHelper::print_setting_error(
array(
'id' => 'frm_leave_email_error',
'errors' => array(
'invalid' => __( 'Email is invalid', 'formidable' ),
'empty' => __( 'Email is empty', 'formidable' ),
),
'class' => 'frm-justify-center frm-items-center',
)
);
?>
</div>
</div>

Expand Down
8 changes: 8 additions & 0 deletions classes/views/frm-settings/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<input class="frm_with_left_label frm8" type="text" name="frm_default_email" id="frm_default_email" value="<?php echo esc_attr( $frm_settings->default_email ); ?>" />
</p>

<p class="frm_grid_container">
<label class="frm4 frm_form_field" for="frm_from_email">
<?php esc_html_e( 'Default From Address', 'formidable' ); ?>
<?php FrmAppHelper::tooltip_icon( __( 'The "From" address for emails sent from this site.', 'formidable' ) ); ?>
</label>
<input class="frm_with_left_label frm8" type="text" name="frm_from_email" id="frm_from_email" value="<?php echo esc_attr( $frm_settings->from_email ); ?>" />
</p>
Comment thread
Crabcyborg marked this conversation as resolved.

<?php
ob_start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,42 @@
</div>

<div class="frm-card-box-content frm-fields">
<h2 class="frm-card-box-title frmcenter"><?php esc_html_e( 'Default Email Address', 'formidable' ); ?></h2>
<h2 class="frm-card-box-title frmcenter"><?php esc_html_e( 'Email Setup', 'formidable' ); ?></h2>
<p class="frm-card-box-text frmcenter">
<?php esc_html_e( 'Set the default email address to receive notifications for new form submissions. You can change this at any time.', 'formidable' ); ?>
<?php esc_html_e( 'Setup the sender address shown to recipients (from) and the default email for admin notifications (to).', 'formidable' ); ?>
</p>

<div class="frm_form_field frm-mt-lg">
<p>
<label for="frm-onboarding-default-email-field"><?php esc_html_e( 'Default email address', 'formidable' ); ?></label>
<label for="frm-onboarding-from-email"><?php esc_html_e( 'From Address', 'formidable' ); ?></label>
<input type="email" name="frm-onboarding-from-email" id="frm-onboarding-from-email" class="frm-input-field frm-gap-xs" placeholder="<?php esc_attr_e( 'Enter your email', 'formidable' ); ?>" value="<?php echo esc_attr( FrmAppHelper::get_settings()->from_email ); ?>" />
<?php
FrmAppHelper::print_setting_error(
array(
'id' => 'frm-onboarding-from-email-error',
'errors' => array(
'invalid' => __( 'Email is invalid', 'formidable' ),
'empty' => __( 'Email is empty', 'formidable' ),
),
)
);
?>
</p>
<p>
<label for="frm-onboarding-default-email-field"><?php esc_html_e( 'To Address', 'formidable' ); ?></label>
<input type="email" name="frm-onboarding-default-email-field" id="frm-onboarding-default-email-field" class="frm-input-field frm-gap-xs" placeholder="<?php esc_attr_e( 'Enter your email', 'formidable' ); ?>" value="<?php echo esc_attr( FrmAppHelper::get_settings()->default_email ); ?>" />
<!-- Email Error -->
<span id="frm-onboarding-email-step-error" class="frm-validation-error frm-mt-xs frm_hidden">
<span frm-error="invalid"><?php esc_html_e( 'Email is invalid', 'formidable' ); ?></span>
<span frm-error="empty"><?php esc_html_e( 'Email is empty', 'formidable' ); ?></span>
</span>
<?php
FrmAppHelper::print_setting_error(
array(
'id' => 'frm-onboarding-email-step-error',
'errors' => array(
'invalid' => __( 'Email is invalid', 'formidable' ),
'empty' => __( 'Email is empty', 'formidable' ),
),
)
);
?>
</p>

<?php if ( ! $pro_is_installed ) { ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@
</div>

<!-- Error Handling -->
<span id="frm-onboarding-check-pro-installation-error" class="frm-validation-error frm-mt-xs frm_hidden">
<span><?php esc_html_e( 'Formidable Pro is currently inactive!', 'formidable' ); ?></span>
</span>
<?php
FrmAppHelper::print_setting_error(
array(
'id' => 'frm-onboarding-check-pro-installation-error',
'errors' => __( 'Formidable Pro is currently inactive!', 'formidable' ),
)
);
?>

<div class="frm-cta frm-cta-border frm-cta-green frm-p-sm frm-mt-sm">
<span class="frm-banner-title frm-font-semibold frm-flex">
Expand Down
2 changes: 1 addition & 1 deletion js/form-templates.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/formidable_blocks.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/formidable_styles.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/onboarding-wizard.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions js/src/onboarding-wizard/elements/getDOMElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function getDOMElements() {
const emailStep = {
setupEmailStepButton: document.getElementById( `${PREFIX}-setup-email-step-button` ),
defaultEmailField: document.getElementById( `${PREFIX}-default-email-field` ),
defaultFromEmailField: document.getElementById( `${PREFIX}-from-email` ),
subscribeCheckbox: document.getElementById( `${PREFIX}-subscribe` ),
summaryEmailsCheckbox: document.getElementById( `${PREFIX}-summary-emails` ),
allowTrackingCheckbox: document.getElementById( `${PREFIX}-allow-tracking` )
Expand Down
25 changes: 19 additions & 6 deletions js/src/onboarding-wizard/events/setupEmailStepButtonListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,35 @@ function addSetupEmailStepButtonEvents() {
onClickPreventDefault( setupEmailStepButton, onSetupEmailStepButtonClick );
}

const validateEmails = emailInputs => {
let isValid = true;
emailInputs.forEach( input => {
const emailAddress = input.value.trim();
if ( ! isValidEmail( emailAddress ) ) {
showEmailAddressError( 'invalid', input );
isValid = false;
}
});
return isValid;
};

/**
* Handles the click event on the "Next Step" button in the "Default Email Address" step.
*
* @private
* @param {Event} event The click event object.
*
* @return {void}
*/
const onSetupEmailStepButtonClick = async() => {
const { defaultEmailField } = getElements();
Comment thread
truongwp marked this conversation as resolved.
const email = defaultEmailField.value.trim();
const { defaultEmailField, defaultFromEmailField } = getElements();

// Check if the email is valid
if ( ! isValidEmail( email ) ) {
showEmailAddressError( 'invalid' );
// Check if the emails are valid
if ( ! validateEmails( [ defaultFromEmailField, defaultEmailField ] ) ) {
return;
}

const { subscribeCheckbox, summaryEmailsCheckbox, allowTrackingCheckbox } = getElements();
const email = defaultEmailField.value.trim();

// Check if the 'subscribe' checkbox is selected. If so, proceed to add the user's email to the active campaign
if ( subscribeCheckbox?.checked ) {
Expand All @@ -53,6 +64,7 @@ const onSetupEmailStepButtonClick = async() => {
// Capture usage data
const { emailStepData } = getAppState();
emailStepData.default_email = email;
emailStepData.from_email = defaultFromEmailField.value.trim();
emailStepData.allows_tracking = allowTrackingCheckbox.checked;
emailStepData.summary_emails = summaryEmailsCheckbox.checked;
if ( subscribeCheckbox ) {
Expand All @@ -63,6 +75,7 @@ const onSetupEmailStepButtonClick = async() => {
// Prepare FormData for the POST request
const formData = new FormData();
formData.append( 'default_email', email );
formData.append( 'from_email', defaultFromEmailField.value.trim() );
formData.append( 'allows_tracking', allowTrackingCheckbox.checked );
formData.append( 'summary_emails', summaryEmailsCheckbox.checked );

Expand Down
10 changes: 6 additions & 4 deletions js/src/onboarding-wizard/ui/showError.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* Internal dependencies
*/
import { PREFIX } from '../shared';
import { showFormError } from '../utils';

/**
* Displays errors related to the email address field.
*
* @param {string} type The categorization of the error (e.g., "invalid", "empty").
* @since x.x Added the `input` param.
*
* @param {string} type The categorization of the error (e.g., "invalid", "empty").
* @param {HTMLInputElement} input The input element to which the error is related.
* @return {void}
Comment thread
truongwp marked this conversation as resolved.
*/
export const showEmailAddressError = type => {
showFormError( `#${PREFIX}-default-email-field`, `#${PREFIX}-email-step-error`, type );
export const showEmailAddressError = ( type, input ) => {
Comment thread
Crabcyborg marked this conversation as resolved.
showFormError( `#${input.id}`, `#${input.nextElementSibling.id}`, type );
};