auto populate a text field when creating a new record?

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 21, 2012   (RSS)

Re: [gord] auto populate a text field when creating a new record?

By Dave - January 21, 2012

Hi Gord,

Sure, try this:
- Edit your section under: Admin > Section Editors
- Edit the text field you want to store the random value in
- For "Default Value" enter: <?php echo uniqid(); ?>
- Then click on your section in the menu and click "Create"
- Confirm that the field shows a random value when creating new records

Let me know if that works for you. if it does, you can just replace uniqid() with a call to your code or functions.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] auto populate a text field when creating a new record?

By gord - January 21, 2012 - edited: January 21, 2012

Hi Dave,

Thanks so much - this is more or less exactly what I was thinking. It just didn't occur to me I could embed php directly into the default value field like that!

What would the be the best way to include a custom function, short of pasting it all into the default value field? Will I have a problem by modifying the admin.php file to include my own function(s)?

Thanks again!

Re: [gord] auto populate a text field when creating a new record?

By Dave - January 21, 2012

Hi Gord,

Probably the easiest way to include a custom function would be with something like this:
<?php include "/path/to/your/custom/file.php"; ?>

Avoid modifying the program files if you can because if you want to upgrade later your changes might get overwritten.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com