Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

This error message "Missing argument 2 for validateInput()"

Explorer ,
Sep 19, 2012 Sep 19, 2012

I created a function safe variable (preg_replace) so I can keep my form a little more secured. The function validateinput has the "safe" but when I process my contact form, I get this error. The form submits the info to my email but I don't know why i'm getting that error.

Warning: Missing argument 2 for validateInput(), called in D:\Hosting\9777689\html\process.php on line 122 and defined in D:\Hosting\9777689\html\process.php on line 108

Here is my php code

            <?php 

            

            function displayRequired($fieldName) {

                echo " \".$fieldName\"is required.<br />n";

            }

            

            function validateInput($data, $fieldName){

                global $errorCount;

                if (empty($data)){

                    displayRequired($fieldName);

                    ++$errorCount;

                    $retval = "";

                } else {

                    $retval = trim($data);

                    $retval = stripslashes($retval);

                }

                return ($retval);

            }

            

            

            $Name = validateInput(safe($_POST['name'], "First Name"));

            $Email = validateInput(safe($_POST['email'], "Email"));

            $Comments = validateInput(safe($_POST['comments'], "Comments"));

                              $Company = validateInput(safe($_POST['company'], "Company"));

                              $Position = validateInput(safe($_POST['position'], "Position"));

            $Phone = safe($_POST['phone']);

           

            

            

            if ($errorCount>0){

                echo "Please re-enter the information below.<br />\n";

                redisplayForm($Name, $Email, $Phone, $Company, $Position, $Comments);

            }

            else

            

            {    

                $To = "";

                $Subject = "";

                $From = "";

            

                                        

                                         $Message .= "Name:  " . $Name . "\n";

                                         $Message .= "Email: " . $Email. "\n\n";

                                            $Message .= "Phone Number: " . $Phone . "\n\n\n";

                                         $Message .= "The name of the company  " . $Company . "\n\n\n\n";

                                         $Message .= "The person company position: " . $Position . "\n\n\n\n\n";

                                         $Message .= "Comments: " . $Comments . "\n\n\n\n\n\n\n";

                                        

                                        

                $Headers = "From: ". $From . "<" . $To. ">\r\n";  

                $Headers .= "Reply-To: " . $Email . "\r\n"; 

                $Headers .= "Return-path: ". $Email;

                $result = mail($To, $Subject, $Message, $Headers);

                if ($result)

                    $resultMsg = "You message was sucessfully sent.";

                    else

                    $resultMsg = "There was a problem sending your message.";

                    

                ?>

                    <h2 style="text-align:center; font-family:Verdana, Geneva, sans-serif; color:#000000">Thank You!</h2>

                    <p style="line-height:200%; text-align:center; font-family:Verdana, Geneva, sans-serif; color:#000000"> for contacting Division 9

<?php

                        if(!empty($fieldName)) {

                            echo " , {$fieldName}. {$resultMsg}";

                        }

                        

                    echo "</p>";

                }

                ?>

    

           

            <?php

               function redisplayForm($Name, $Email, $Phone, $Company, $Position, $Comments){

            

            ?>

           

           

           

    <form action="process.php" method="post">

            <fieldset class="first">

            <label class="labelone" for="name">Name:</label><!--css rule-->

            <input type="text" name="name" value="<?php echo $Name; ?>" /> 

            <label for ="email">Email:</label>

            <input type="text" name="email" value="<?php echo $Email; ?>" />

            <label for="phone">Phone:</label>

            <input type="text" name="phone" value="<?php echo $Phone; ?>"/>

            <label for="company">Enter the name of your company:</label>

            <input type="text" name="company" value="<?php echo $Company; ?>"/>

           

            <label for="position">Enter your company position:</label>

            <input type="text" name="position" value="<?php echo $Position; ?>"/>

           

            <label for="comments">Comments:</label>

            <textarea name="comments" value="<?php echo $Comments; ?>"></textarea>

           

             <?php

          require_once('recaptchalib.php');

          $publickey = "6LedpNYSAAAAAEEqxEtMn88haDtxmB0YgwREX6c-"; // you got this from the signup page

          echo recaptcha_get_html($publickey);

                  ?>

            </fieldset>

            <fieldset>

            <input class="btn" name="submit" type="submit" value="Send Email"/>

            <input class="btn" name="reset" type="reset" value="Clear Form" />

            </fieldset>

            </form>

                    <?php

            }

            ?>

<?php

function safe($string)

          {

                    $pattern = "/\r|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i";

                    return preg_replace($pattern, '', $string);

          }

?>

Your assistance will be greatly appreciated.

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

Generally, this means that one of your functions accepts 2 arguments. But when you call that function, you're only sending 1 argument.

Check your code again to see if you have a code snippet where you're only sending 1 argument to the function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

atlnycdude24 wrote:

I created a function safe variable (preg_replace) so I can keep my form a little more secured. The function validateinput has the "safe" but when I process my contact form, I get this error. The form submits the info to my email but I don't know why i'm getting that error.

Warning: Missing argument 2 for validateInput(), called in D:\Hosting\9777689\html\process.php on line 122 and defined in D:\Hosting\9777689\html\process.php on line 108

It's because validateInput() expects two arguments, but you're passing it only one. Look at your code again. This is what you have:

            $Name = validateInput(safe($_POST['name'], "First Name"));

            $Email = validateInput(safe($_POST['email'], "Email"));

            $Comments = validateInput(safe($_POST['comments'], "Comments"));

                              $Company = validateInput(safe($_POST['company'], "Company"));

                              $Position = validateInput(safe($_POST['position'], "Position"));

Instead of passing two arguments to validateInput(), you're passing two arguments to safe(). Your closing parenthesis is in the wrong place. This is what you should have:

$Name = validateInput(safe($_POST['name']), "First Name");

$Email= validateInput(safe($_POST['email']), "Email");

$Comments = validateInput(safe($_POST['comments']), "Comments");

$Company = validateInput(safe($_POST['company']), "Company");

$Position = validateInput(safe($_POST['position']), "Position");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 19, 2012 Sep 19, 2012

David, you da man!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 23, 2012 Sep 23, 2012
LATEST

David and Sudarshan, thanks for your assisstance guys!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines