Jump to content

Recommended Posts

So I'm using the CakePHP application framework on my local server with PHP5. I don't know if any of you are familiar with it but I've tried getting help from the cakephp website but nobody knew so I thought I'd ask here.

 

For some reason, using CakePHP's validate function does not work on my server when it works on others. Another person sent me an exact copy of some code he had on his server using the same version of CakePHP and the PHP 5 but his would validate and mine wouldn't. What happens is, the validate function is supposed to check to see if data is alphaNumeric and of a certain length, but instead, mine does not do this and inserts blank entries into the database instead of displaying errors.

 

So my question is, what could be wrong with my server (PHP settings or apache settings or something) that would cause this to not validate? I know it's definitely something wrong with my server and don't have a clue what it'd be. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/
Share on other sites

Well it is all relevant to CakePHP so a lot of you won't know how it works and the exact same code works for another person so I don't think there's anything wrong with the code, just something with my version of PHP or apache or something. But if you insist:

 

A test validation form I tried (written by someone who knows a lot about cakephp and worked for them)

<?php // View for the form - what the page looks like ?>
<h2>Add Option</h2>

<form method="post" action="">
<p><?php echo $form->input('Option.name'); ?></p>
<p><?php echo $form->input('Option.value'); ?></p>
<?php echo $form->submit('Submit'); ?>
</form>

<?php

// Application model  - where the validation takes place

class Option extends AppModel
{
    var $name = 'Option';

// Validation
var $validate = array(
	'name' => array(
		'rule' => array('custom', '/\\w/'),
		'allowEmpty' => false,
		'message' => 'Please enter a valid name.'
	),
	'value' => array(
		'rule' => array('custom', '/\\w/'),
		'allowEmpty' => false,
		'message' => 'Please enter a valid value.'
	)
);
}
?>

<?php
// Controller for the application
class OptionsController extends AppController
{
var $name = 'Options';

function add()
{
	if ( !empty($this->data) )
	{
		$this->Option->set($this->data);

		if ( $this->Option->save($this->data) )
		{
			echo "saved";
		}
		else {
			echo "failed validation";
		}
	}
}
}
?>

Have you done a "view source" of the form in your browser to make sure the fields are correct? Have you echoed the variables in your code that receive the values from the form to see what they contain? These would be the first two troubleshooting steps to pin down what area the problem is in (the form or the data reaching the form processing code.)

  • 2 weeks later...
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.