This topic is locked

Automatic zerofill

10/25/2007 10:37:36 AM
PHPRunner General questions
V
vytb author

Hello.
May somebody explain how to (automatically) zero fill in entry form?

J
Jane 10/26/2007

Hi,
you can set up 0 as default value for your fields on the "Edit as" settings dialog on the Visual Editor tab or use Before record added/Before record updated events for this purpose.

V
vytb author 10/26/2007

Hi,

you can set up 0 as default value for your fields on the "Edit as" settings dialog on the Visual Editor tab or use Before record added/Before record updated events for this purpose.



It is not a problem. However, how to set the field to make the format say 0000 in order to get 0001 instead of 1 when you write 1?

J
Jane 10/26/2007

Vitas,
to display field in your format on the list/view page use Custom option on the "View as" settings dialog.

Here is a sample code:

if ($value<10)

$value = "000".$value;

if ($value>9 && $value<100)

$value = "00".$value;

if ($value>99 && $value<1000)

$value = "0".$value;

V
vytb author 10/26/2007

Thanks Jane, however the code for the list page does not affect codes in add/edit pages, thus zeros are not included in concatenation. How to solve this?

kujox 10/28/2007

Thanks Jane, however the code for the list page does not affect codes in add/edit pages, thus zeros are not included in concatenation. How to solve this?


You might be better looking at some javascript that will format the input box and make the table field a varchar,
If it's a number it will drop any leading zeros but you could put them back in with $value = str_pad($value,4,"0",STR_PAD_LEFT); in the visual editor in a custom option

V
vytb author 10/29/2007



You might be better looking at some javascript that will format the input box and make the table field a varchar,
If it's a number it will drop any leading zeros but you could put them back in with $value = str_pad($value,4,"0",STR_PAD_LEFT); in the visual editor in a custom option


Thanks a lot,
If I do this your way, zeros are still stripped before/while concat. However it's OK if I include str_pad in the concat formula.

M
mmhsymon 6/23/2009



Thanks a lot,
If I do this your way, zeros are still stripped before/while concat. However it's OK if I include str_pad in the concat formula.


str_pad(string,length,pad_string,pad_type) worked !!

but one problem. when i export in excel then 0 does not added
where the problem ????

J
Jane 6/24/2009

Hi,
I recommend you to publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.