• Resolved Jeremy Edmiston

    (@jeremyedmiston)


    In looking to quickly add new expenses without returning to list view, I added a button to the edit-payment screen and modified class-ajax to handle the addnew value in edit_payment function. This could obviously be added to all entry screens, possibly cleaner, but the presence of a second submit button cannot be distinguished in the $_REQUEST variables.

    edit-payment.php: add field

    eaccounting_hidden_input(
    	array(
    		'name'  => 'addnew'
    	)
    );

    edit-payment.php: after submit button

    <button type="button" name="submitnew" id="submitnew" class="button button-secondary">Save and Add Another</button>

    edit-payment.php: in eaccounting_enqueue_js

    jQuery('#ea-payment-form #submitnew').click(function(){
    	jQuery('#ea-payment-form #addnew').val(true);
    	jQuery('#ea-payment-form').submit();
    });

    class-ajax.php: edit_payment() at line 874

    $addnew = empty( $posted['addnew'] ) ? false : true;
    $redirect = '';
    if ( ! $update ) {
      $message  = __( 'Payment created successfully!', 'wp-ever-accounting' );
      if ($addnew){
        $redirect = eaccounting_clean( $referer );
      }else{
        $redirect = remove_query_arg( array( 'action' ), eaccounting_clean( $referer ) );
      }
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @jeremyedmiston,

    Thanks for reaching out.

    In your class-ajax.php file, make sure to handle the ‘addnew’ parameter in the $_REQUEST array. You can differentiate the “Save and Add Another” action based on the ‘submitnew’ button’s name attribute.

    $addnew = isset( $_REQUEST['addnew'] ) && $_REQUEST['addnew'] === 'true';
    
    $redirect = '';
    if ( ! $update ) {
        $message  = __( 'Payment created successfully!', 'wp-ever-accounting' );
        if ($addnew) {
            $redirect = eaccounting_clean( $referer );
        } else {
            $redirect = remove_query_arg( array( 'action' ), eaccounting_clean( $referer ) );
        }
    }
    

    Let us know if this helps.

    Hi,

    I’ll close this ticket for now but if you still need assistance with it, you can open a new support thread and I’ll help you there.

    Thanks for using WP Ever Accounting plugin. Have a great day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Save and Add New (Expense)’ is closed to new replies.