Jump to content

getting variables out of functions.


spires

Recommended Posts

Hi

 

I have place my form error code inside a function so I can reuse it through out the site.

I am returning the errors, but I also want to return a 2nd variable.

This will place a star next to the fields that have not been filled in.

 

 

The Function:

function message_errors($message, $errors){
  
  $output = "";
  $star = array();
  if (!empty($message)) {
	  $output .= "<p class=\"message\">" . $message . "</p>";
  }
  
  if (!empty($errors)) {
	  $output .= "<p class=\"errors\">";
	  foreach ($errors as $error) {
		  $output .= " - " . $error . "<br />";
		  $star[] = $error;
	  }
	  $output .= "</p>";
  }	
   return $output;
}

 

 

The Form:

<?PHP 
$message = message_errors($message, $errors);
        echo $message;	
?>
<form action="edit_subject.php?subj=<?PHP echo urlencode($sel_subject['id']); ?>" method="POST">
     <p>Subject name: <?PHP if (in_array('menu_name',$star)) { echo "*"; }?>
     <input type="text" name="menu_name" value="<?PHP echo $sel_subject['menu_name']; ?>" id="menu_name" />
      </p>
     <p>Subject position: <?PHP if (in_array('position',$star)) { echo "*"; }?>
     <input type="text" name="position" value="<?PHP echo $sel_subject['position']; ?>" id="position" />
      </p>
</form

 

 

I can only get the returned output from the function, how do I also get the variable $star out as well?

 

 

Thanks for your help

Link to comment
https://forums.phpfreaks.com/topic/198359-getting-variables-out-of-functions/
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.