Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Gabriel Reguly

    (@gabriel-reguly)

    Hi Scott,

    Can you paste your shortcode here?

    Regards,
    Gabriel

    Thread Starter scottydog0

    (@scottydog0)

    Sure, here’s what I’m using:

    [phone* Phone mask:999-999-9999]

    -Scott

    Plugin Author Gabriel Reguly

    (@gabriel-reguly)

    Hi Scott,

    Apologies for the delay.

    Your mask is not working because the way CF7 deals with the parentesis.

    If I put a mask like this

    [phone* Phone mask:(99)9-999-9999] CF7 parses it as

    Array
    (
        [type] => phone*
        [name] =>
        [options] => Array
            (
            )
    
        [raw_values] => Array
            (
            )
    
        [values] => Array
            (
            )
    
        [pipes] =>
        [labels] => Array
            (
            )
    
        [attr] => Phone mask:(99)9-999-9999
        [content] =>
    )

    but if the mask has no parentesis, e.g. [phone* Phone mask:999-999-9999] the result from CF7 parser is

    Array
    (
        [type] => phone*
        [name] => Phone
        [options] => Array
            (
                [0] => mask:999-999-9999
            )
    
        [raw_values] => Array
            (
            )
    
        [values] => Array
            (
            )
    
        [pipes] => WPCF7_Pipes Object
            (
                [pipes] => Array
                    (
                    )
    
            )
    
        [labels] => Array
            (
            )
    
        [attr] =>
        [content] =>
    )

    I’ll have to think about a way to deal with both situations.

    Regards,
    Gabriel

    Thread Starter scottydog0

    (@scottydog0)

    I looked at your code. Maybe something like this:

    $tokens = array( 'mask' => 'mask:', 'alternate_mask' => 'aMask:', 're_do' => 'reDo:', 're_undo' => 'reUndo:');
    
    if (!empty( $tag['attr']) {
    	foreach($tokens as $var => $token){
    		if (strpos($token, $tag['attr'])) {
    			${$var} = preg_replace("/.*?$token([^\s]+)\s.*/",'$1',$tag['attr']);
    		} else {
    			${$var} = '';
    		};
    	};
    } else if (!empty($tag['options'])) {
    	foreach ($tag['options'] as $value) {
    		foreach($tokens as $var => $token){
    			if (strpos($token, $value)) {
    				${$var} = preg_replace("/.*?$token([^\s]+)\s.*/",'$1',$value);
    			} else if(!isset(${$var})) {
    				${$var} = '';
    			};
    		};
    	};
    };

    I haven’t tested it yet, so my regex may be off, but this should properly parse out the options in either situation.

    Plugin Author Gabriel Reguly

    (@gabriel-reguly)

    Hi Scott,

    Thanks for the code.

    However there are other situations where the plugin is failing, for example, when one uses ‘watermarks’ or when one use masks with spaces.

    I am thinking about removing the Tag Generator panel and creating a new menu entry for just the masks.

    It won’t be so tightly integrated to Contact Form 7, but it would be a way to solve all those issues.

    How does it sound to you? Seems that is would be good or bad?

    Regards,
    Gabriel

    Thread Starter scottydog0

    (@scottydog0)

    I’m not sure about “watermarks”. I’d need to see an example. I think keeping things tightly integrated is probably best. A separate interface could get confusing. What problem have you had w/ spaces so far? Have you tried using a space character placeholder?

    Thanks,
    Scott

    Plugin Author Gabriel Reguly

    (@gabriel-reguly)

    Hi Scott,

    Watermarks are part of CF7:
    https://www.ads-software.com/support/topic/plugin-contact-form-7-how-to-add-watermark-to-text-field?replies=2

    The issue with spaces is that I use them as a separator for the mask options, I am not keen using a placeholder because it would defeat the purpose of having simple shortcodes.

    In hindsight, I would not remove the Tag Generator panel, instead just the mask options.

    Those would go in a separate panel.

    Thanks to all your input and help.

    Would you like to see a preview of the new version?

    Regards,
    Gabriel

    Thread Starter scottydog0

    (@scottydog0)

    Sure, I’d like to see the new version.

    Thanks,
    Scott

    Plugin Author Gabriel Reguly

    (@gabriel-reguly)

    Hi Scott,

    The new version of Contac Form 7 allows telephone fields, so I am thinking of changing the purpose of this plugin to masks only.

    Currently I am overloaded with work, but once I can start on this I will contact you again.

    Regards,
    Gabriel

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Mask doesn't work without brackets’ is closed to new replies.