Jump to content

Recommended Posts

Hello, I am writing a validate function that works by passing the post value, the type of field and if the field is required. In my register page I call the function like:

 

<?php
validate($_POST['username'],'username',1);
?>

 

The function is stored in a separate functions page in a functions directory. The code for the function is as folllows:

 

<?php 
function validate($post_value,$field_type,$required){
if(isset($_POST[$post_value]) && (!empty($post_value)) || !$required){

}else{

}
?>

 

I have included the functions page with

 

<?php
include 'functions/functions.php';
?>

 

But yet when I debug or run the code it seems as if my code can't see the function even though it enters the functions.php file. Have you guys got any ideas why this would be happening?

Link to comment
https://forums.phpfreaks.com/topic/149794-call-to-undefined-function/
Share on other sites

Your function is wrong anyway.

 

It should read.

 

function validate($post_value,$field_type,$required)
{
if(isset($post_value) && !empty(trim($post_value)) || !$required)
        {

}
        else
        {

}
}

 

This might in turn fix the problem so worth a try :).

I would like to have a validation class, but the only OOP experience I've had in the past is Java. I'm not sure how PHP implements polymorphism, inheritance and encapsulation. This project is only for a small website and it is easier for me to code a small function that to learn OOP rules in PHP and then code a class.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.