Form Tools
Default Value for Fields - Printable Version

+- Form Tools (https://forums.formtools.org)
+-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1)
+--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17)
+--- Thread: Default Value for Fields (/showthread.php?tid=191)



Default Value for Fields - spenny - Jun 24th, 2009

Hi, can anyone tell me how I set a field to have a default value?

Usually I would do this by writing value="myvalue" but I am already using this 'value' to make the form sticky eg as follows:

Code:
<input type="text" name="myfield" size="10" maxlength="15" value="<?=@$fields['myfield']?>"/>

Thanks in advance!


RE: Default Value for Fields - Ben - Jun 26th, 2009

Hi Spenny,

Try this:

Quote:<?php $val = (isset($fields['myfield'])) ? $fields['myfield'] : "DEFAULT VALUE!"; ?>
<input type="text" name="myfield" size="10" maxlength="15" value="<?=$val?>"/>

All the best -

Ben


RE: Default Value for Fields - spenny - Jul 25th, 2009

Hi Ben,

Many thanks for providing the answer.