form numbering sequence example 1-450 then after 450, will reset to 1 again

dhan0315

New Member
Hello everyone, I have a question if it is possible to have form numbering like for example.

after form 1 submitted successfully, it will have (counter number)=field type 1 then
the if next sender will submit the form again, then this will have counter number 2 and so on.
then after the form counter number reached 450 records submitted. the counter number will reset it to 1 again


this this condition:

if (form = submit successfully) {
if (counter number >=450) {
counter number = 1; }​
else {
counter number = counter number +1; }​
}

thank you in advance for your inputs. God bless!
 
there is a sequence element plugin for such things (numbering invoices for example).
 
there is a sequence element plugin for such things (numbering invoices for example).
thank you for your suggestion. I used already sequence element plugin. its pretty good to having sequence number but my question was it possible to reset the sequence to 1 after reaching 450??
 
You probably need two elements, something like: "number_of_set" and "counter_number". "Counter_number" would be a calc element where you calculate your number like:

Select maximum number_of_set.
Select maximum counter_number amongst maximum number_of_set.

if (maximum counter_number == 450) {
counter number = 1
number_of_set = maximum number_of_set + 1
} else {
counter number = maximum counter_number + 1
number_of_set = maximum number_of_set
}

And obviously you need to adjust the code like adding correct select queries etc.
 
You probably need two elements, something like: "number_of_set" and "counter_number". "Counter_number" would be a calc element where you calculate your number like:

Select maximum number_of_set.
Select maximum counter_number amongst maximum number_of_set.

if (maximum counter_number == 450) {
counter number = 1
number_of_set = maximum number_of_set + 1
} else {
counter number = maximum counter_number + 1
number_of_set = maximum number_of_set
}

And obviously you need to adjust the code like adding correct select queries etc.
honestly i don't know exactly where querries to add and pull out the record
 
Sequences are stored in a fabrik table (#___fabrik_sequences) which is pretty easy to update using a cron or a php onAfterProcess to modify. That what I use to reset the sequence every month (using cron in my case)...
In your case a small script could check the value and reset to 1 in case it reach 451....
 
tha
Sequences are stored in a fabrik table (#___fabrik_sequences) which is pretty easy to update using a cron or a php onAfterProcess to modify. That what I use to reset the sequence every month (using cron in my case)...
In your case a small script could check the value and reset to 1 in case it reach 451....
thank you for the idea
 
PHP:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('seque')
    ->from('fab_senders_form')
    ->where('id = ' . $myDb->quote('control_no'));

$myDb->setQuery($myQuery);
$lastSequence = $myDb->loadResult();
return $lastSequence;

any idea what is wrong with this code, I'm actually trying to load the last sequence value from the last submitted form. but no display at all

J version: 3.10.11
Fabrik version: 3.10

thank you for the ideas
 
What is your current table setup? Do you have "set number" column like I suggested above. Or just the counter_number column (guess this is "seque")? If you have several sets of numbers from 1-450 without "set number" column, your result will always be 450.

At least you need to add MAX to your query "->select(MAX('seque'))" to not to get multiple values.
thank you. what i did here is that i'm trying to load value from the last record (seque field).

PHP:
$ctrInc='{fab_senders_form___ctrl_inc}';

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('seque')
    ->from('fab_senders_form')
    ->where('id = ' . $myDb->quote($ctrInc));

$myDb->setQuery($myQuery);
$fieldA = $myDb->loadResult();
return $fieldA;

this exactly what i want to display the last value of seque saved, i guess 'where' function is missing something. when i tried to put numbers like '301' (which was the last id) fixed number, got the result of seque last value. actually the 'fab_senders_form___ctrl_inc' - this is the calc who retrive the last id value.

i'm trying to set query where 'id' = fab_senders_form___ctrl_inc (which is the last record).

if got the last record (seque) example seque value last record is '5'

from this i will create condition

if seque == 450
seque=1
else
seque = seque+1

then will save the record with seque value 6 since the last was 5 and so on.

i think finding the last record sort by id will help to determine the condition where to add +1 or reset to 1


i don't know if it is understandable. Thanks you for your answer anyway
 
Last edited:
Your code should ordered desc on id and send last id. Something like :
PHP:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('seque')
    ->from('fab_senders_form')
     ->order('id DESC')
    ->setLimit('1')
;

$myDb->setQuery($myQuery);
$lastSeq = $myDb->loadResult();
return $lastSeq;
 
Your code should ordered desc on id and send last id. Something like :
PHP:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('seque')
    ->from('fab_senders_form')
     ->order('id DESC')
    ->setLimit('1')
;

$myDb->setQuery($myQuery);
$lastSeq = $myDb->loadResult();
return $lastSeq;

WOW great! it worked. that's what i need. thank you so much guys for your inputs. BIG HELP!
 
Last edited:
Your code should ordered desc on id and send last id. Something like :
PHP:
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select('seque')
    ->from('fab_senders_form')
     ->order('id DESC')
    ->setLimit('1')
;

$myDb->setQuery($myQuery);
$lastSeq = $myDb->loadResult();
return $lastSeq;

one more question, i created php onload process in this form with ths codes. just to update the seque field, but it's failed to display any number., i don't know where to adjust the codes or where exactly need to put the php or js code

PHP:
$lastseq = $formModel->formData['fab_senders_form___last_seq_raw'];

if ($lastseq == "450")
{
  $formModel->data['fab_senders_form___seque']='0';

}else {

  $formModel->data['fab_senders_form___seque']=$lastseq + 1;
}
thanks again!
 
You should try these lines (one after each other) before your own code to figure out what data are available
PHP:
echo "<pre>";print_r($formModel->data);exit;
or
echo "<pre>";print_r($formModel->formData);exit;
or
echo "<pre>";print_r($data);exit;
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top