PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | stripe/controllers/FrmTransLiteActionsController.php +69 -12 6.27 → trunk View file →
@@ -105,9 +105,9 @@
105 105 $class_name = 'Frm' . $class_name . 'ActionsController';
106 106 $response = $class_name::trigger_gateway( $action, $entry, $form );
107 107
108 108 if ( ! $response['success'] && $response['show_errors'] ) {
109 - // the payment failed
109 + // The payment failed
110 110 self::show_failed_message( compact( 'action', 'entry', 'form', 'response' ) );
111 111 }
112 112 }
113 113
@@ -268,8 +268,9 @@
268 268
269 269 if ( ! in_array( $trigger_event, $allowed_triggers, true ) ) {
270 270 $trigger_event = $payment->status === 'complete' ? 'payment-success' : 'payment-failed';
271 271 }
272 +
272 273 FrmFormActionsController::trigger_actions( $trigger_event, $entry->form_id, $entry->id );
273 274 }
274 275
275 276 /**
@@ -282,13 +283,15 @@
282 283 */
283 284 public static function prepare_description( &$action, $atts ) {
284 285 $description = $action->post_content['description'];
285 286
286 - if ( $description ) {
287 - $atts['value'] = $description;
288 - $description = FrmTransLiteAppHelper::process_shortcodes( $atts );
289 - $action->post_content['description'] = $description;
287 + if ( ! $description ) {
288 + return;
290 289 }
290 +
291 + $atts['value'] = $description;
292 + $description = FrmTransLiteAppHelper::process_shortcodes( $atts );
293 + $action->post_content['description'] = $description;
291 294 }
292 295
293 296 /**
294 297 * Convert the amount into 10.00.
@@ -407,8 +410,9 @@
407 410 $settings_for_action = array(
408 411 'id' => $payment_action->ID,
409 412 'first_name' => $payment_action->post_content['billing_first_name'],
410 413 'last_name' => $payment_action->post_content['billing_last_name'],
414 + 'address' => $payment_action->post_content['billing_address'] ?? '',
411 415 'gateways' => $payment_action->post_content['gateway'],
412 416 'fields' => self::get_fields_for_price( $payment_action ),
413 417 'one' => $payment_action->post_content['type'],
414 418 'email' => $payment_action->post_content['email'],
@@ -453,13 +457,9 @@
453 457 'post_status' => 'publish',
454 458 );
455 459 $payment_actions = FrmFormAction::get_action_for_form( $form_id, 'payment', $action_status );
456 460
457 - if ( ! $payment_actions ) {
458 - $payment_actions = array();
459 - }
460 -
461 - return $payment_actions;
461 + return $payment_actions ? $payment_actions : array();
462 462 }
463 463
464 464 /**
465 465 * Make sure a gateway field is hidden on the front end.
@@ -473,8 +473,14 @@
473 473 if ( $field->type !== 'gateway' ) {
474 474 return $values;
475 475 }
476 476
477 + if ( FrmAppHelper::is_form_builder_page() ) {
478 + // The hooks this uses can get called in the form builder and settings pages.
479 + // But we do not need the script in this case.
480 + return $values;
481 + }
482 +
477 483 // This is also called from the frm_enqueue_form_scripts hook.
478 484 // With this here, the value of frm_stripe_vars.settings[0].fields is -1
479 485 // This is because the amount value is processed and a shortcode is not found in '000'.
480 486 FrmStrpLiteActionsController::load_scripts( (int) $field->form_id );
@@ -589,8 +595,14 @@
589 595 $settings['credit_card'] = $credit_card_field_id;
590 596 }
591 597 }
592 598
599 + if ( ! in_array( 'stripe', $settings['gateway'], true ) ) {
600 + // We only need a gateway field for Stripe add-on compatibility,
601 + // so unless Stripe is selected, we can return early.
602 + return $settings;
603 + }
604 +
593 605 $gateway_field_id = FrmDb::get_var(
594 606 'frm_fields',
595 607 array(
596 608 'type' => 'gateway',
@@ -635,9 +647,54 @@
635 647 *
636 648 * @return false|int
637 649 */
638 650 protected static function add_a_field( $form_id, $field_type, $field_name ) {
639 - $new_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
640 - $new_values['name'] = $field_name;
651 + $new_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id );
652 + $new_values['name'] = $field_name;
653 + $new_values['field_order'] = self::get_field_order_before_submit( $form_id, $new_values['field_order'] );
641 654 return FrmField::create( $new_values );
655 + }
656 +
657 + /**
658 + * When auto-injecting a field, ensure it is placed before the submit button.
659 + *
660 + * @since 6.29
661 + *
662 + * @param int $form_id
663 + * @param int $field_order
664 + *
665 + * @return int
666 + */
667 + private static function get_field_order_before_submit( $form_id, $field_order ) {
668 + $submit_field = FrmSubmitHelper::get_submit_field( $form_id );
669 +
670 + if ( ! $submit_field || $field_order < (int) $submit_field->field_order ) {
671 + return $field_order;
672 + }
673 +
674 + $submit_order = (int) $submit_field->field_order;
675 + FrmField::update( $submit_field->id, array( 'field_order' => $submit_order + 1 ) );
676 + return $submit_order;
677 + }
678 +
679 + /**
680 + * Remove credit card validation errors.
681 + *
682 + * @param array $errors
683 + * @param stdClass $field
684 + *
685 + * @return array
686 + */
687 + public static function remove_cc_errors( $errors, $field ) {
688 + $field_id = $field->temp_id ?? $field->id;
689 +
690 + if ( isset( $errors[ 'field' . $field_id . '-cc' ] ) ) {
691 + unset( $errors[ 'field' . $field_id . '-cc' ] );
692 + }
693 +
694 + if ( isset( $errors[ 'field' . $field_id ] ) ) {
695 + unset( $errors[ 'field' . $field_id ] );
696 + }
697 +
698 + return $errors;
642 699 }
643 700 }