Advertisement:

Author Topic: using validator fom hValidate.php  (Read 2380 times)

rpedretti

  • Newbie
  • *
  • Posts: 28
using validator fom hValidate.php
« on: August 10, 2011, 11:06:15 pm »
Hi there!!

Is there a way to show a message at validation fail like the ones built-in in osclass but using the validators from hValidate.php and stop/revert the item addition?

Thanks!
« Last Edit: August 10, 2011, 11:08:20 pm by rpedretti »

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: using validator fom hValidate.php
« Reply #1 on: August 11, 2011, 03:45:24 pm »
for example, what do you want to achieve?

rpedretti

  • Newbie
  • *
  • Posts: 28
Re: using validator fom hValidate.php
« Reply #2 on: August 11, 2011, 09:27:00 pm »
I want to validate some fields added by my plugin. But it's required to be validated in PHP, not in JS. So, when the user add/edit an item, i validate the fields and, if there is something wrong, i want to do the same as osclass does, like showing the message on the top of the page and return to item add/edit.

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: using validator fom hValidate.php
« Reply #3 on: August 12, 2011, 01:22:57 pm »
I would use pre_item_post hook. I'll put an example of how it should be:


function check_plugin_parameters( ) {
    
$error false;

    
// check parameter
    
if( Params::getParam('horse') == '' ) {
        
$error true;
        
osc_add_flash_error_message__('Horse field cannot be blank''{plugin_domain}') ) ;
    }


    if(!
$error) return true;

    
header'Location: ' osc_item_post_url() );
}

osc_add_hook('pre_item_post''check_plugin_parameters') ;

rpedretti

  • Newbie
  • *
  • Posts: 28
Re: using validator fom hValidate.php
« Reply #4 on: August 12, 2011, 05:55:49 pm »
Hi!

This solution is working partially. I can check the fields before post, but its not preventing the post nor showing the error message.

I've done as the example, only not using the __() function, internationalization not required.

Thanks!

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: using validator fom hValidate.php
« Reply #5 on: August 12, 2011, 05:59:19 pm »
Can you send me the plugin? Or just upload here?

rpedretti

  • Newbie
  • *
  • Posts: 28
Re: using validator fom hValidate.php
« Reply #6 on: August 12, 2011, 06:39:14 pm »
Here it is!

The functions name and text string are in portuguese

If needed I can translate to english.

rpedretti

  • Newbie
  • *
  • Posts: 28
Re: using validator fom hValidate.php
« Reply #7 on: August 18, 2011, 11:10:00 pm »
I managed to make it work by adding a 'exit()' at the end. I think it's not right, but worked. It just don't keep the input values.

Code: [Select]
function check_fields() {
$error = false;
$tipo = get_cat_name($_POST['catId']);
if (!isset($_POST['curso'])){
$error = true;
osc_add_flash_error_message('some text');
}
if(!isset($_POST['matutino']) && !isset($_POST['vespertino']) && !isset($_POST['noturno'])){
$error = true;
osc_add_flash_error_message('other text');
}
if($_POST['carga_horaria'] == ''){
$error = true;
osc_add_flash_error_message('yat');
}

if(intval($_POST['carga_horaria']) < 0){
$error = true;
osc_add_flash_error_message('one more text');
}

if($tipo == 'Estágio' && $_POST['obrigatorio'] == 'nobrigatorio' && intval($_POST['carga_horaria']) > 20){
$error = true;
osc_add_flash_error_message('text text');
}

if(!$error) return true;

header( 'Location: ' . osc_item_post_url() );

exit();
}

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: using validator fom hValidate.php
« Reply #8 on: August 22, 2011, 12:53:52 pm »
It's ok... you should add the exit(); at the end.