Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
auto populate a text field when creating a new record?

 

 


gord
New User

Jan 21, 2012, 11:00 AM

Post #1 of 4 (1534 views)
Shortcut
auto populate a text field when creating a new record? Can't Post

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


Dave
Staff / Moderator


Jan 21, 2012, 12:23 PM

Post #2 of 4 (1528 views)
Shortcut
Re: [gord] auto populate a text field when creating a new record? [In reply to] Can't Post

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
 


gord
New User

Jan 21, 2012, 1:09 PM

Post #3 of 4 (1521 views)
Shortcut
Re: [Dave] auto populate a text field when creating a new record? [In reply to] Can't Post

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!


(This post was edited by gord on Jan 21, 2012, 1:12 PM)


Dave
Staff / Moderator


Jan 21, 2012, 3:10 PM

Post #4 of 4 (1516 views)
Shortcut
Re: [gord] auto populate a text field when creating a new record? [In reply to] Can't Post

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