Search code examples
phpphpmailer

Uncaught ArgumentCountError: Too few arguments to function phpfmg_hsc(), 1


I am very sorry to be asking for help and it's been a while since I last did that.

In general I find my own solutions however I recently switched my website PHP version 7.0 and it seems that the mail send form is no longer working as a result.

The error I receive is:

Fatal error:  Uncaught ArgumentCountError: Too few arguments to function phpfmg_hsc(), 1 passed in contact2/indexnl.php on line 61 and exactly 2 expected in form.lib.php:1244
Stack trace:
#0 indexnl.php(61): phpfmg_hsc('field_1')
#1 form.lib.php(193): phpfmg_form('')
#2 indexnl.php(9): phpfmg_display_form()
#3 {main}
  thrown in /public_html/contact2/form.lib.php on line 1244

In these lines i have: #0

    <textarea name="field_1" id="field_1" rows=4 cols=25 class='text_area'><?php  phpfmg_hsc("field_1"); ?></textarea>

#1

     phpfmg_header( $title, $keywords, $description );
        if( !$isHideForm ){
            phpfmg_form($sErr);
        }else{
            phpfmg_thankyou();
        };
        phpfmg_footer();
    
        return;
    }

#2

    phpfmg_display_form();

#3

    function phpfmg_hsc($field, $default){
        echo isset($_POST[ $field ])
             ? HtmlSpecialChars( $_POST[ $field ] )
             : $default;
    }

I'm sorry for asking what I'm sure for a lot of you higher level programmers is stupid, but can someone please help me out? I really have tried to understand it, but I don't.

I look forward to your help.

-Isaac


Solution

  • I would hazzard a guess that this has always been an error, but when you changed versions of PHP the new php.ini has got error reporting turned on.

    #3 tells you how to fix this!

    The second parameter is what it should use as a default if the input field has not previously been set.

    So change all calls to phpfmg_hsc() to have a default, the simplest solution would be to do

    phpfmg_hsc('field_1', '') 
    

    to signify to leave the field empty

    You might consider changing the function itself like this, but as that code is not yours, that might not be the best idea as if you ever update that addin your problem will come back.

    function phpfmg_hsc($field, $default=''){
        echo isset($_POST[ $field ])
             ? HtmlSpecialChars( $_POST[ $field ] )
             : $default;
    }