Loading ...
Sorry, an error occurred while loading the content.

Re: Custom input validation - error messages - ErrorMessagePrefix showing twice

Expand Messages
  • fen.strat
    Hi Manuel, ... form_custom_test_class.php : class form_custom_test_class extends form_custom_class { var $client_validate = 0; var $server_validate = 1;
    Message 1 of 5 , Feb 10 4:28 PM
    • 0 Attachment
      Hi Manuel,

      > Can you provide a minimal example that I can reproduce the problem?


      form_custom_test_class.php :
      class form_custom_test_class extends form_custom_class {
      var $client_validate = 0;
      var $server_validate = 1;

      function AddInput(&$form, $arguments) {
      $input_arguments = array(
      'ID'=>$arguments['ID'].'_',
      'NAME'=>$arguments['ID'].'_',
      'TYPE'=>'text',
      'LABEL'=>$arguments['LABEL']
      );
      $form->AddInput($input_arguments);
      return '';
      }

      function ValidateInput(&$form) {
      return 'Custom Input Validation Error Message.';
      }

      }


      test.php
      require('forms.php');
      require('form_custom_test_class.php');
      require('form_layout_vertical.php');

      // Instantiate Form
      $form = new form_class;
      $form->NAME = 'custom_test_form';
      $form->METHOD = 'GET';
      $form->ACTION = '';
      $form->ShowAllErrors = 1;
      $form->ErrorMessagePrefix = '- ';

      // Add Inputs
      $form->AddInput(array(
      'TYPE'=>'text',
      'ID'=>'normal_input',
      'NAME'=>'normal_input',
      'LABEL'=>'Normal Input',
      // 'ValidateAsNotEmpty'=>1,
      'ValidationErrorMessage'=>'Normal Input Validation Error Message.',
      'ValidateOnlyOnServerSide'=>1
      ));
      $form->AddInput(array(
      'TYPE'=>'custom',
      'CustomClass'=>'form_custom_test_class',
      'ID'=>'custom_input_1',
      'LABEL'=>'Custom Input 1'
      ));
      $form->AddInput(array(
      'TYPE'=>'custom',
      'CustomClass'=>'form_custom_test_class',
      'ID'=>'custom_input_2',
      'LABEL'=>'Custom Input 2'
      ));
      $form->AddInput(array(
      'TYPE'=>'hidden',
      'ID'=>'process_form',
      'NAME'=>'process_form',
      'VALUE'=>1
      ));
      $form->AddInput(array(
      'TYPE'=>'submit',
      'ID'=>'btn_submit',
      'VALUE'=>'Submit',
      ));

      // Process Form (if submitted)
      if ($form->WasSubmitted('process_form')) {
      if (($error_html = $form->Validate($verify)) != '') {
      echo '<pre>'.$error_html.'</pre>';
      }
      }

      // Layout Form
      $form->AddInput(array(
      'ID'=>'layout',
      'NAME'=>'layout',
      'TYPE'=>'custom',
      'CustomClass'=>'form_layout_vertical_class',
      'Inputs'=>array(
      'normal_input',
      'custom_input_1_',
      'custom_input_2_',
      'process_form',
      'btn_submit'
      )
      ));

      // Display Form
      $form->StartLayoutCapture();
      $form->AddInputPart('layout');
      $form->EndLayoutCapture();
      $form->DisplayOutput();


      If you submit the form with no input values, you'll notice that the first error displayed is missing the ErrorMessagePrefix.

      If the first field to validate is NOT a custom field (i.e. uncomment 'ValidateAsNotEmpty'=>1 for the normal_input), then there is no problem and the prefix is displayed for each error.

      If this is run with form.php from 2007-06-02 (the last release) then, for the custom inputs, no prefixes are displayed and each error is outputted twice.

      Hope this helps in tracking it down.
      Thanks in advance,
      Saul
    • Manuel Lemos
      Hello, ... Ok, I fixed the bug. You find the fixed version here. Thank you for reporting.
      Message 2 of 5 , Feb 11 6:04 PM
      • 0 Attachment
        Hello,

        on 02/10/2008 10:28 PM fen.strat said the following:
        > If you submit the form with no input values, you'll notice that the
        > first error displayed is missing the ErrorMessagePrefix.
        >
        > If the first field to validate is NOT a custom field (i.e. uncomment
        > 'ValidateAsNotEmpty'=>1 for the normal_input), then there is no problem
        > and the prefix is displayed for each error.
        >
        > If this is run with form.php from 2007-06-02 (the last release) then,
        > for the custom inputs, no prefixes are displayed and each error is
        > outputted twice.

        Ok, I fixed the bug. You find the fixed version here. Thank you for
        reporting.

        http://www.meta-language.net/cvs/forms/forms.php?rev=HEAD;content-type=application%2Foctet-stream

        --

        Regards,
        Manuel Lemos

        PHP professionals looking for PHP jobs
        http://www.phpclasses.org/professionals/

        PHP Classes - Free ready to use OOP components written in PHP
        http://www.phpclasses.org/
      • fen.strat
        Works perfect, thanks Manuel Cheers, Saul
        Message 3 of 5 , Feb 11 7:03 PM
        • 0 Attachment
          Works perfect, thanks Manuel

          Cheers, Saul
        Your message has been successfully submitted and would be delivered to recipients shortly.