• Hello,
    
    Can anyone help me with my problem? We had this custom plugin in a while and we noticed that when the user put special characters, it will trigger infinite loop on the server or the server/page just keep on loading.
    
    My question is how can I restrict the user on inputting special characters on the specific field.
    
    Here is a sample code from the custom plugin.
    
    // checkout page, show purchase order field
    
    add_action( 'woocommerce_after_order_notes', 'pof_purchase_order_field' );
    function pof_purchase_order_field( $checkout ) {
    print 'Purchase Order NEW
    
    '.PHP_EOL; woocommerce_form_field( '_purchase_order', array( 'type' => 'text', 'class' => array('pof_purchase_order_field form-row-wide'), 'label' => 'Purchase Order', 'placeholder' => 'Purchase Order', 'required' => false, 'maxlength' => 15, ), $checkout->get_value( '_purchase_order' )); print ''.PHP_EOL;
    } // end function
    
    // place order, validate the purchase order field
    add_action('woocommerce_checkout_process', 'pof_validate_purchase_order_field');
    function pof_validate_purchase_order_field() {
    return;
    // check if set, if its not set add an error.
    if ( ! $_POST['_purchase_order'] ) {
    wc_add_notice( 'The Purchase Order field may not be empty.', 'error' );
    }
    } // end function
    
    // save order, save purchase order field
    
    add_action( 'woocommerce_new_order', 'pof_new_order' );
    function pof_new_order( $order_id ) {
    if( isset( $_POST['_purchase_order'] ) ) {
    $purchase_order = $_POST['_purchase_order'];
    $previous_value = get_post_meta( $order_id, '_purchase_order', true );
    update_post_meta( $order_id, '_purchase_order', $purchase_order, $previous_value );
    }
    } // end function
    
    // thankyou and view order pages, show purchase order field
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Infinite loop when inserting special character’ is closed to new replies.