Mask doesn't work without brackets
-
Hi,
This plugin is great, but I’ve found an issue when changing the phone mask. It seems that when I use a mask like “999-999-9999” instead of “(999)999-9999”, the phone mask comes out as blank.
Thanks,
Scotthttp://ww.wp.xz.cn/extend/plugins/contact-form-7-phone-mask-module/
-
Hi Scott,
Can you paste your shortcode here?
Regards,
GabrielSure, here’s what I’m using:
[phone* Phone mask:999-999-9999]
-Scott
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 asArray ( [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 isArray ( [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,
GabrielI 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.
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,
GabrielI’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,
ScottHi Scott,
Watermarks are part of CF7:
http://ww.wp.xz.cn/support/topic/plugin-contact-form-7-how-to-add-watermark-to-text-field?replies=2The 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,
GabrielSure, I’d like to see the new version.
Thanks,
ScottHi 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
The topic ‘Mask doesn't work without brackets’ is closed to new replies.