Next Random Record Button (link) to load data on form

?
Guest 23 Sep, 2011
hi ALL Iam using Chronoform V4 and i need php code or any method to add only next button to load the next Random data record , i am new in php i try to change the token value inside the url but it fail😟😟

please help me🙂
thanks in advance🙂
GreyHead 24 Sep, 2011
Hi r2awm,

You can do this in the On Load event when the form Loads.

If you have a small (< 500 records) table then you can use "ORDER BY RAND() LIMIT 1" in the MySQL query. You may be able to do this with the DB REcord Loader action by putting an ORDER by command in the WHERE box (it would need to be preceded by a valid WHERE statement e.g. 1 = 1 if you aren't already using one).

It the table is bigger this method apparently gets very slow and you'd need to use a couple of linked MySQL statements. You could put these into a Custom Code action. The syntax is something like the code shown in this article I found with Google. Note that the exact code depends a lot on how your table is structured and the records that exist in it. If you have a autoincremented primary key and every id exists in the table it's a lot simpler.

Bob
?
Guest 25 Sep, 2011
HI GreyHead,

thanks:) now i can view my data record randomly on submit😉
but can u tell me how i can load the data on it is text fields😑

thanks again😉
GreyHead 27 Sep, 2011
Hi r2awm,

Make sure that the DB Record Loader action is before the Show HTML action.

Make sure that the input names in your form match the column names in the database record.

That should be all.

Bob
?
Guest 27 Sep, 2011
Hi Bob🙂

my DB Loader is already before show html , and i checked the input names in my form it match the column names in the database record but when i click on submit it still load the data on the web page not to its text field😟
GreyHead 28 Sep, 2011
Hi r2awm,

I don't understand this: "it still load the data on the web page not to its text field"???

Please post a link to the form so I can take a quick look.

Bob
?
Guest 28 Sep, 2011
Hi Bob ,

sorry for the bad explanation from my side, i tried to use the random function and it works normally but the code call the function through (print_r) command and this will print the result on the page .. how to load the record in its proper text box😑

sorry but am still a beginner in this field😑

thanks in advance😉
GreyHead 28 Sep, 2011
Hi r2awm ,

Please see the DB Record Loader tutorial. I think it is in the DownLoads area here.

Bob
?
Guest 29 Sep, 2011
Hi Bob,

first i would like to thank you for your continuing support🙂 but i still have a problem this is a short brief of what i need :
(loading the record randomly and when the user submitted it will not be load on the form anymore)🙂

First try :
i read the tutorial and i followed all the steps in it , i realized that i can control the load of data record by pass the token variable into URL . i use this method by writing the below code:

<?php
$db=&JFactory::getDBO();
$sql="select count(*) from jos_chronoforms_data_test1"; 
$db->setQuery($sql);
$result=$db->loadResult();
$random_num = rand(1,$result);
$url ='index.php?option=com_chronoforms&chronoform=test1&token='.$random_num.'';
$url = JRoute::_($url);
?>
<input type=button value="Next" onclick="location.href='<?php echo $url?>'" ></input>


the form working fine and now the form load the record randomly on submit😉 but i could not remove the record submitted by user ??:(

second try:
i wrote the (Random code) you give it to me and it works fine but as i told you the data records does not loaded on its places on the form (on the event there is DB loader and custom code (call the random function ) and show HTML there is something missing:(

third try:
in the tutorial i read that there is a method to load the data by put {field_name} into a form code to be replaced by the value of the same field from the record loaded,(this is what i need) but where i can put it?? on the value attribute for each input ?? or at the top of the form code ???
please advise me😟

thanks in advance🙂
GreyHead 29 Sep, 2011
Hi r2awm,

I'm very sorry but I don't understand what this means.

loading the record randomly and when the user submitted it will not be load on the form anymore



I've read your post a couple of times but am not sure what your question is :-(

Bob
?
Guest 29 Sep, 2011
Hi Bob ,

there is no problem Bob, but can you tell me where should i put {field_name}
?
Guest 29 Sep, 2011
Hi Bob ,

sorry but i have many questions and many ideas soo i can't describe what i need😟
but for my question it was ( the random function will load the data randomly i want to remove the submitted record from the range of the random function😟
GreyHead 29 Sep, 2011
Hi r2awm,

That is difficult. I guess that you'd need to add some kind of flag into the table and set the query to ignore any records with the flag set.

Bob
?
Guest 29 Sep, 2011
Hi Bob ,

ok thank you Bob ,i got it😉
now can you tell where should i write the {field_name} to be replaced by the value of the same field from the record loaded🙂
GreyHead 30 Sep, 2011
Hi r2awm,

I think that you can use {input_name} anywhere in a Custom code element or in the Form HTML if you are not using the Wizard for that. And the value will automatically be substituted if there is a form input with the same name.

Bob
?
Guest 30 Sep, 2011
Hi Bob,

start of all, sorry for bothering you,
on the other hand :
I did as you told me i confirmed that the {field_name} has the same name of the (input name) , but the form still did not load any data .
my form settings are as the following :

-on (onload events) there is :
1- DB Loader (DB-field:(cf_id),Table(my table name),request parameter:(token) andloads fields(yes))
2- custome code. i wrote ({my_field_name})
3- Show HTML .

can you tell me where is the missing point😟

thanks in advance🙂
?
Guest 01 Oct, 2011
Hi Bob,

please i need your help what should i write on the custom code
my inputs name are : agent_name and customer_name

should i write :{agent_name},{customer_name}
or
agent_name={agent_name}
customer_name = {customer_name}
GreyHead 09 Oct, 2011
Hi r2awm,

I'm sorry but I don't understand where you want to use these values?

Please tell me exactly what you are trying to do here. I've read back through the thread but just get confused :-(

Bob
This topic is locked and no more replies can be posted.