Pretty simple. I'm trying to call a function from within my controller. The function is, in fact, defined. Yet, when the function is called I get "PHP Fatal Error: Call to undefined function validate() ..."
Here's my code. Any ideas? Thanks.
<?php
class HomeController extends BaseController {
/**
* Controller for the index action of the home page. Displays the landing page.
*/
public function index()
{
return View::make('landing', array('success' => false));
}
/**
* Controller to handle processing the contact form and re-displaying the landing page
*/
public function processForm()
{
$form_array = array();
$errors = array();
foreach (array('email','fname','lname','message','newsletter') as $val)
{
if (isset($_POST[$val]))
$form_array[$val] = $_POST[$val];
else
$form_array[$val] = null;
}
$form_ok = validate();
if ($form_ok)
{
echo "GOOD!";
}
else
{
echo "BAD!";
}
}
/**
* Helper function for validating the form. Returns true if the form was
* submitted without errors.
*/
public function validate()
{
return true;
}
}
It looks like you're trying to call $this->validate()
, instead of validate()
. You've defined validate()
as a class method, not a stand alone function.
You should try to refer to the actual controller.
Both of these will work.
$form_ok = self::validate();
or
$this->validate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With