How to use minihaku (5)

Date 2006-09-04 18:06:39 | Category: XOOPS

in englishin japanese
How to hide birth-year.
This is a practice to use checkboxes.

I. do ALTER TABLE

ALTER TABLE (prefix)_users ADD display_birthyear tinyint not null default 0;

II. edit templates

minihaku_edituser.html (edit minihaku_register.html too, if necessary)

<input type="checkbox" name="display_birthyear" id="display_birthyear" <{if $display_birthyear}>checked="checked"<{/if}> /><label for="display_birthyear">display your age</label>


III. write logics into include/config.php

III-B define extra fields

$extra_fields = array(
	'sex' => array(
		'initval' => -1 ,
		'options' => array( 0 => 'male' , 1 => 'female' ) ,
		) ,
	'birth' => array(
		'initval' => '1950-01-01' ,
		) ,
	'display_birthyear' => array(
		'initval' => false ,
		) ,
	) ;


III-C Initialization and Query Part


if( empty( $minihaku_uid4whr ) ) {
	foreach( $extra_fields as $key => $attribs ) {
		$allowed_requests[$key] = $attribs['initval'] ;
	}
} else {
	$db =& Database::getInstance() ;
	list( $allowed_requests['sex'] , $allowed_requests['birth'] , $allowed_requests['display_birthyear'] ) = $db->fetchRow( $db->query( "SELECT sex,birth,display_birthyear FROM ".$db->prefix("users")." WHERE uid=$minihaku_uid4whr" ) ) ;
	$allowed_requests['sex'] = intval( $allowed_requests['sex'] ) ;
	$allowed_requests['display_birthyear'] = (bool)$allowed_requests['display_birthyear'] ;

	// for the plugin of modifier.minihaku_userinfo.php
	$fields4html['sex'] = $extra_fields['sex']['options'][ $allowed_requests['sex'] ] ;
	$fields4html['birth'] = str_replace( '-' , '/' , $allowed_requests['birth'] ) ;
	if( ! $allowed_requests['display_birthyear'] ) $fields4html['birth'] = substr( $fields4html['birth'] , 5 ) ;
}

Notice the cast (bool).
This is the MUST casting if you use a checkbox.

You can hide/display "birthday" by a similar procedure.




You can read more news at PEAK XOOPS.
http://xoops.peak.ne.jp

The URL for this story is:
http://xoops.peak.ne.jp/md/news/index.php?page=article&storyid=358