can you help me guys? i have a problem in PHP... how to fix this problem?
Parse error: syntax error, unexpected T_CASE in /home/... /class.CForm.php on line 197
line 197 is:
case "post" :
$values = $_POST;
break;
this is the full source..
<?php
class CForm
{
public $_name = "";
public $_method = "";
public $_constants = array( );
public $_titles = array( );
public $_comments = array( );
public $_enctype = "multipart/form-data";
public $_errors = array( );
public $_fields = array( );
public $_rules = array( );
public $_values = array( );
public $_validation_failed = false;
public $_known_elements = array( 'select' => array( 'copy_value' => "selected" ), 'radio' => array( 'copy_value' => "selected" ), 'checkbox' => array( 'copy_value' => "checked" ), 'button' => array( 'copy_value' => false ), 'submit' => array( 'copy_value' => false ), 'print' => array( 'copy_value' => false ), 'date' => array( 'copy_value' => true, 'custom_processing' => "date" ), 'time' => array( 'copy_value' => true, 'custom_processing' => "time" ), 'file' => array( 'copy_value' => false, 'custom_processing' => "file" ) );
public $_rule_handlers = array( '=' => "rule_equal", '>' => "rule_greater", '<' => "rule_less", '>=' => "rule_greater_eq", '<=' => "rule_less_eq", 'between' => "rule_between", 'betweeneq' => "rule_between_eq", 'required' => "rule_required", 'compare' => "rule_compare", 'not_empty' => "rule_not_empty", 'maxlen' => "rule_maxlen", 'dehtml' => "rule_dehtml", 'trim' => "rule_trim", 'type' => "rule_type", 'function' => "rule_function" );
public $_rule_error_handlers = array( 'continue' => "rule_error_continue", 'skip' => "rule_error_skip" );
public function __construct( $name = "", $method = "POST" )
{
$this->_name = $name;
$this->_method = $method;
}
...
public function set_titles( $titles, $value = null )
{
if ( !is_array( $titles ) )
{
if ( !is_string( $titles ) )
{
return;
}
$this->_titles[$titles] = $value;
}
else
{
$this->_titles = array_merge( $this->_titles, $titles );
}
}
public function set_comments( $comments, $value = null )
{
if ( !is_array( $comments ) )
{
if ( !is_string( $comments ) )
{
return;
}
$this->_comments[$comments] = $value;
}
else
{
$this->_comments = array_merge( $this->_comments, $comments );
}
}
public function getconst( $const )
{
if ( isset( $this->_constants[$const] ) )
{
return $this->_constants[$const];
}
else
{
return $const;
}
}
public function _( $const )
{
return $this->getconst( $const );
}
public function add_field( $type, $name, $value = null, $attribs = array( ) )
{
$new_field = array( "type" => $type, "name" => $name, "required" => false );
if ( $value !== null )
{
$new_field['value'] = $value;
}
if ( $attribs )
{
$new_field['attribs'] = $attribs;
}
$this->_fields[$name] = $new_field;
}
public function add_rule( $fields, $type, $params = null, $error_msg = null, $on_error = null )
{
if ( !is_array( $fields ) )
{
if ( $fields == "" )
{
return;
}
$fields = array( $fields );
}
if ( !count( $fields ) )
{
return;
}
foreach ( $fields as $field )
{
if ( $field == "" )
{
continue;
}
$not = false;
if ( $type[0] == "!" )
{
$type = substr( $type, 1 );
$not = true;
}
if ( $type == "required" && isset( $this->_fields[$field] ) )
{
$this->_fields[$field]['required'] = true;
}
$this->_rules[$field][] = array( "type" => $type, "params" => $params, "error_msg" => $error_msg, "on_error" => $on_error, "not" => $not );
}
}
public function fetch( &$PARENT, $block_name )
{
$this->_fields[] = array( "type" => "hidden", "name" => "form_name", "value" => $this->_name );
run_block( "fetch_form", &$PARENT, $block_name, null, $this );
}
public function fetch_form( &$RESULT, $vars )
{
$RESULT['type'] = "formdata";
$RESULT['data']['name'] = $this->_name;
$RESULT['data']['method'] = $this->_method;
$RESULT['data']['enctype'] = $this->_enctype;
foreach ( $this->_fields as $field )
{
run_block( "fetch_element", &$RESULT, "elements['".$field['name']."']['htmlcode']", array( "field" => $field ), $this );
}
}
public function fetch_element( &$RESULT, $vars )
{
$RESULT['data'] = $vars['field'];
$RESULT['type'] = "form_".$RESULT['data']['type'];
$RESULT['data']['title'] = $this->_titles[$RESULT['data']['name']]( $this->_titles[$RESULT['data']['name']] );
$RESULT['data']['comment'] = $this->_comments[$RESULT['data']['name']]( $this->_comments[$RESULT['data']['name']] );
$RESULT['data']['error'] = $this->_errors[$RESULT['data']['name']]( $this->_errors[$RESULT['data']['name']] );
$attribs = "";
if ( isset( $RESULT['data']['attribs'] ) )
{
foreach ( $RESULT['data']['attribs'] as $attr_name => $attr_value )
{
$attribs .= " ".$attr_name."=\"".$attr_value."\"";
}
}
$RESULT['data']['attributes'] = $attribs;
$RESULT['parent']['data']['elements'][$RESULT['data']['name']] = $RESULT['data'];
}
public function validate( )
{
$values = array( );
case "post" :
$values = $_POST;
break;
case "get" :
$values = $_GET;
break;
$this->_validation_failed = false;
if ( $values['form_name'] != $this->_name )
{
return false;
}
$this->_values = $values;
foreach ( $this->_fields as $row )
{
if ( isset( $this->_known_elements[$row['type']]['custom_processing'] ) )
{
$custom_processing = $this->_known_elements[$row['type']]['custom_processing'];
}
else
{
$custom_processing = false;
}
if ( $custom_processing )
{
switch ( $custom_processing )
{
case "date" :
$el_name = $row['name'];
$el_value = $this->_values[$el_name."_Year"]."-".$this->_values[$el_name."_Month"]."-".$this->_values[$el_name."_Day"];
$this->_values[$el_name] = $el_value;
break;
case "time" :
$el_name = $row['name'];
$hour = $this->_values[$el_name."_Hour"];
$minute = $this->_values[$el_name."_Minute"];
$second = $this->_values[$el_name."_Second"];
$meridian = $this->_values[$el_name."_Meridian"];
$hour = isset( $hour ) ? $hour : 0;
$minute = isset( $minute ) ? $minute : 0;
$second = isset( $second ) ? $second : 0;
if ( ( integer ) <= 12 && isset( $meridian ) )
{
$meridian = strtolower( $meridian );
if ( $hour == 12 )
{
$hour = 0;
}
if ( $meridian == "pm" )
{
$hour += 12;
if ( $hour == 24 )
{
$hour = 0;
}
}
}
$el_value = date( "H:i:s", mktime( $hour, $minute, $second ) );
$this->_values[$el_name] = $el_value;
break;
case "file" :
$el_name = $row['name'];
$this->_values[$el_name] = $_FILES[$el_name]['size'];
break;
}
}
}
...
}
?>