<?xml version="1.0"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>MachForm Community Forums Topic: Random number as a field's default value</title>
<link>https://www.machform.com/forums/</link>
<description>MachForm Community Forums Topic: Random number as a field's default value</description>
<language>en</language>
<pubDate>Sun, 03 May 2026 21:00:08 +0000</pubDate>

<item>
<title>agdm619 on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-24595</link>
<pubDate>Sun, 20 Dec 2015 05:06:30 +0000</pubDate>
<dc:creator>agdm619</dc:creator>
<guid isPermaLink="false">24595@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;Works Great!!! Thanks so much! &#60;/p&#62;
&#60;p&#62;Although, when you're filling out the form and you get to the review page, it shows the random number (which is great), but if you decide to click previous to correct something and then continue back to the review page the random number changes. Any we to stop it from changing once it generated?&#60;/p&#62;
&#60;p&#62;Thanks for everything!&#60;/p&#62;
&#60;p&#62;Aaron
&#60;/p&#62;</description>
</item>
<item>
<title>yuniar on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-24576</link>
<pubDate>Wed, 16 Dec 2015 09:23:44 +0000</pubDate>
<dc:creator>yuniar</dc:creator>
<guid isPermaLink="false">24576@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;You'll only need to adjust the if statement a little bit, like this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if($form_id == 7 &#38;#38;&#38;#38; $is_edit_page !== true){
   $table_data[&#38;#39;element_5&#38;#39;] = FLOOR(1001 + RAND() * 8998);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;That should prevent the code being executed when you're editing the entry in the backend.
&#60;/p&#62;</description>
</item>
<item>
<title>agdm619 on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-24574</link>
<pubDate>Wed, 16 Dec 2015 01:36:08 +0000</pubDate>
<dc:creator>agdm619</dc:creator>
<guid isPermaLink="false">24574@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;I know this an very old post, but it does seem to work in 4.6 its now located on line 1969-1970&#60;/p&#62;
&#60;p&#62;My question is, although it works, if you edit the entry in the back-end it will change the randomized number again. Is there anyway to stop this from happening with like a  - if(empty($var)) statement? I'm not a programmer so forgive my ignorance.&#60;/p&#62;
&#60;p&#62;In my thinking, if there were a way for it to check and see if the field was populated it would be not change it. Or in other words - if empty then run $table_data['element_1'] = FLOOR(210 + RAND() * 300); if populated then ignore.&#60;/p&#62;
&#60;p&#62;Please help!&#60;/p&#62;
&#60;p&#62;Thanks!&#60;br /&#62;
Aaron
&#60;/p&#62;</description>
</item>
<item>
<title>bonda on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-12752</link>
<pubDate>Tue, 11 Oct 2011 22:52:50 +0000</pubDate>
<dc:creator>bonda</dc:creator>
<guid isPermaLink="false">12752@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;Thank you, Andar!
&#60;/p&#62;</description>
</item>
<item>
<title>yuniar on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-12750</link>
<pubDate>Tue, 11 Oct 2011 19:02:53 +0000</pubDate>
<dc:creator>yuniar</dc:creator>
<guid isPermaLink="false">12750@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;It's pretty easy to do this. You only need to edit &#34;includes/post-functions.php&#34; file.&#60;br /&#62;
Search around line 967-968 and you'll find this block of code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;$table_data[&#38;#39;ip_address&#38;#39;]   = $user_ip_address;
$table_data[&#38;#39;date_created&#38;#39;] = date(&#38;quot;Y-m-d H:i:s&#38;quot;);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Now, let say your form is having id number 7 and you have a number field (admin only field) which having id = &#34;element_5&#34; (view the HTML source of your form to see it).&#60;/p&#62;
&#60;p&#62;Below the above code, add this code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if($form_id == 7){
	$table_data[&#38;#39;element_5&#38;#39;] = FLOOR(1001 + RAND() * 8998);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;that should do it.
&#60;/p&#62;</description>
</item>
<item>
<title>bonda on "Random number as a field's default value"</title>
<link>https://www.machform.com/forums/topic/random-number-as-a-fields-default-value#post-12748</link>
<pubDate>Tue, 11 Oct 2011 01:50:48 +0000</pubDate>
<dc:creator>bonda</dc:creator>
<guid isPermaLink="false">12748@https://www.machform.com/forums/</guid>
<description>&#60;p&#62;I want to attribute to every entry its unique 4-digit ID and put it into an admin-only field. A random number generated by FLOOR(1001 + RAND() * 8998) would do it. But how to get it generated and entered automatically when the entry is created? &#60;em&#62;And&#60;/em&#62; how to make sure it is not regenerated in case of the entry update?
&#60;/p&#62;</description>
</item>

</channel>
</rss>
