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)

By gord - January 21, 2012

Hi,

I'm building a system to enable downloads via a combination of random strings. Basically users will each be assigned a random string, and the files will likewise be assigned a random string. To download their file, the user will enter a string that consists of the two. So far so good, but as I've already got cmsBuilder on my site, I'd like to use it to deploy this system too.

I am trying to figure out the best way of assigning the random strings. Is there a way cmsBuilder can automatically populate a text field in a new record by somehow calling a custom routine (that I would write) that would generate the string?

If not, does anyone else have other ideas about how to implement this?

Thanks,
gord

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: [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