Support » Plugin: Code Snippets » Problem using code in ContactForm

  • Resolved José Milhori



    I had Contact Form routines in my theme footer.php. But suddenly, it stopped working. I researched and had recommendations of this plugin.

    After updating and saving the snippet, it does not make the right consistency. I can not get back to working as the routine was in footer.php. What will be my mistake?

    Snippet updated.

    Name: OnlyNumber


    1 add_action(‘wp_footer’, ‘OnlyNumber’);
    3 ?>
    4 <script>
    5 function OnlyNumber(num) {
    6 var er = /[^0-9.]/;
    7 er.lastIndex = 0;
    8 var campo = num;
    9 if (er.test(campo.value)) {
    10 campo.value = “”;
    11 }
    12 }
    13 </script>
    14 <?php

    In the ContactForm, the field that makes the “call” to the “OnlyNumber” routine:

    <input class=”num_placa” onkeyup=”OnlyNumber(this);” maxlength=”4″ minlength=”4″ size=”4″ type=”text” />

    That is, it accepts letters, numbers, .etc, what the routine would prevent.

    Thank you very much

    José Cláudio Costa (in live Brazil)

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge


    Hi José,

    In order to output JavaScript or HTML code in your page footer, you’ll need to wrap it all in a PHP function:

    add_action( 'wp_footer', function () { ?>
    function OnlyNumber(num) {
    	var er = /[^0-9.]/;
    	er.lastIndex = 0;
    	var campo = num;
    	if (er.test(campo.value)) {
    		campo.value = "";
    <?php } );

    Give the above code a try; I think it should work much better.

    Thread Starter José Milhori


    Hi Shea Bunge (@bungeshea)

    Thank you my friend.
    Now it worked 100%! Thanks for the help.

    Plugin Author Shea Bunge


    No problem; glad to hear that it’s working.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problem using code in ContactForm’ is closed to new replies.