garry Posted June 28, 2008 Share Posted June 28, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/ Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 Can we see some code, preferably, where you retrieve your variables, where you insert to db and where you validate. Ta. Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-576635 Share on other sites More sharing options...
garry Posted June 28, 2008 Author Share Posted June 28, 2008 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"; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-576650 Share on other sites More sharing options...
garry Posted June 28, 2008 Author Share Posted June 28, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-576683 Share on other sites More sharing options...
PFMaBiSmAd Posted June 28, 2008 Share Posted June 28, 2008 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.) Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-576690 Share on other sites More sharing options...
garry Posted June 29, 2008 Author Share Posted June 29, 2008 The data submits fine and the correct data is passed to the model. The problem is that this data is not validated before entering it into the database, which it should be. Can anyone at all help? Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-577101 Share on other sites More sharing options...
vikramjeet.singla Posted July 10, 2008 Share Posted July 10, 2008 will please let me know which version of CakePHP you are using... Quote Link to comment https://forums.phpfreaks.com/topic/112317-cakephp-validation-troubles/#findComment-586130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.