Jump to content

Modifying a function


Kimomaru

Recommended Posts

Hello,

    I have a simple form for user registration that, right now, requires that all fields be filled out.  I would like to change the php code so that two of the fields will not throw an error if they're not filled out (date of birth and middle name), but the rest should be mandatory.  The code looks like this;

 

  $FirstName=$_POST['FirstName'];

  $MiddleName=$_POST['MiddleName'];

  $LastName=$_POST['LastName'];

  $DateOfBirth=$_POST['DateOfBirth'];

  $Email=$_POST['Email'];

  $UserName=$_POST['UserName'];

  $Password=$_POST['Password'];

  $Password2=$_POST['Password2'];

 

  session_start();

  try  {

   

    if (!filled_out($_POST)) {

      throw new Exception('You have not filled the form out correctly - please go back and try again.');

    }

_______________________________

 

function filled_out($form_vars) {

  foreach ($form_vars as $key => $value) {

    if ((!isset($key)) || ($value == '')) {

        return false;

    }

  }

  return true;

}

 

My guess is that the code that needs to be changed is the part that's in bold, but I'm not sure how I can change it to skip the two values that I would like to make optional.  Can someone help?

Link to comment
https://forums.phpfreaks.com/topic/264758-modifying-a-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.