Load the next data record onsubmit

ammari 01 Oct, 2011
Hi All,

am using Chronoform v4 as (wizard), and i need to load the next record (onsubmit) i wrote the below code :

<?php
$db=&JFactory::getDBO();
$MyForm =& CFChronoForm::getInstance('test1');
$current_id = $MyForm->data['cf_id'];
$next_id=$current_id+1;
$url ='index.php?option=com_chronoforms&chronoform=test1&token='.$next_id.'';
$url = JRoute::_($url);
?>

<input type=button value="Next" onclick="location.href='<?php echo $url?>'" ></input>



this is work fine🙂
but is there any method to load data without using the token value , i read the tutorial of loading data there is a method to load data using a curly brakets{field_name} can you tell me where should i put this brakets.
GreyHead 01 Oct, 2011
Hi ammari,

You can use the curly brackets syntax in any HTML you use but not usually in PHP as the PHP is evaluated before the curly bracket values are substituted :-(

Bob
ammari 02 Oct, 2011
Hi Bob,

i write in the custom code {field_name} which i drag it before the DB Loader and after the Show html and set the last option in Show html (curly brackets replacer)to YES , but it does not load any value😟

just show the {field_name} i confirmed that the name is the same as my input name😟
GreyHead 05 Oct, 2011
Hi ammari,

Reading this again the DB Record Loader action needs to come before the Show HTML action. They are run in the sequence they appear.

DB Record Loader
v
Show HTML

Bob
Max_admin 05 Oct, 2011

but is there any method to load data without using the token value



Why ? I see you are building a link to the next record, the link is built ok and as long as you have the correct order of actions as Bob has mentioned then it should load the form fields data ok🙂
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ammari 08 Oct, 2011
Thanks alot🙂

the form works fine;)🙂

but i need to prevent users from opeining the same record. (lock the open record ) how i can do that ???😑

i have an idea to drag a hidden field and set it to 0 if the record open it sets to 1 but can i save this change on database before click the submit button (on load) or somthing like that ????
thanks in advance🙂
GreyHead 08 Oct, 2011
Hi ammari,

You'd need to have a 'lock' column in the database and in the ON Load event add Custom code to query the database' check if this record is locked and if it isn't then lock it. And, as you say, add a hidden input to 'unlock' the record when it is saved again.

This isn't built in to ChronoForms and you'd need to replace the DB Record Load with a Custom Code element.

Bob
ammari 09 Oct, 2011
Thanks alot🙂

now i have a lock column in my database (set 0 value for all records)

on custom code which located on (onload event) can you tell how to check the lock column value should i write this code :


$MyForm =& CFChronoForm::getInstance('My_form_name');
$lock = $MyForm-> data['lock'];// is this get the value saved on my database???


if ($lock == 0)// is this a correct statement ??
{
$lock=1;
$sql="Select col_1,col_2 from my_table_name LIMIT 1 ";
}

there is a hidden field with name of the lock column and the default value is 0 so onsubmit the lock set to 0 again🙂

thanks in advance🙂
GreyHead 09 Oct, 2011
Hi ammari,

In the On Load event you would want something like this
<?php
if ( isset($form->data['lock']) && $form->data['lock'] ) {
  $mainframe =& JFactory::getApplication();
  $mainframe->redirect('form_url', 'This record is locked, please try later');
} else {
  $db =& JFactory::getDBO();
$query = "
  UPDATE `#__some_table`
    SET `lock` = 1
    WHERE `cf_id` = '{$form->data['cf_id']}' ;
";
$db->setQuery($query);
$db->query();
$form->data['lock'] = 0;
?>

Bob
ammari 10 Oct, 2011
thanks alot🙂
but i still have a problem😟

First :

if( isset($form->data['lock'] && $form->data['lock'] ) 
//parse error, expecting `','' or `')'' 

i realize that the missing was the end ")" of the if statement but the error message still exist😟

and can you tell me how can i select the records after this check?? can i start typing my select statement inside the (else statement)???
GreyHead 10 Oct, 2011
Hi ammari,

Sorry, that line should be
if ( isset($form->data['lock']) && $form->data['lock'] ) {


I'd use a separate DB Record Load action to load the data.

Bob
ammari 11 Oct, 2011
Thanks Bob🙂

it works fine😉

now i can lock my record on load😉

the last thing i would asked to you, that i have now random function selection and it work fine and i can lock my record how i can combine these two codes to get my form work as i want

- select random record where lock=0
- set lock=1
- onsubmit lock=0

this is my random selection function :

  function random_row($table, $column) {
       $max_sql = "SELECT max(" . $column . ") 
                  AS max_id FROM " . $table;
      $max_row = mysql_fetch_array(mysql_query($max_sql));
       $random_number = mt_rand(1, $max_row['max_id']);
      $random_sql = "SELECT cf_id,customer_id,customer_code,contact_num,contract_id,customer_name  FROM " . $table . " WHERE " . $column . " >= " . $random_number . "         ORDER BY rand() ASC  LIMIT 1";

      $random_row = mysql_fetch_row(mysql_query($random_sql));

      if (!is_array($random_row)) {

        $random_sql ="SELECT cf_id,customer_id,customer_code,contact_num,contract_id,customer_name  FROM " . $table . " WHERE " . $column . " <" . $random_number . "         ORDER BY rand() ASC  LIMIT 1";

          $random_row = mysql_fetch_row(mysql_query($random_sql));

      }

      return $random_row;

  }
   
$r=random_row('jos_chronoforms_data_push_more_data', 'cf_id');
?>



how i can insert the check for the lock status inside this code , is it possible???
and am sorry for inconvenience but i am still beginner in this field🙂
GreyHead 11 Oct, 2011
Hi ammari,

Please try
WHERE " . $column . " >= " . $random_number . "  AND `lock` = 0 

Bob
ammari 11 Oct, 2011

I'd use a separate DB Record Load action to load the data



sorry bob , but can explian what did you mean ??
ammari 11 Oct, 2011
Big thank for you🙂

but my question was how to lock the record after the random function select it ,which mean where to put the update statement inside the random function to set the lock value to 1

thanks in Advance🙂
This topic is locked and no more replies can be posted.