danielbidala VIP
Total posts: 153
18 Sep 2014 07:13

Hi all!

I would like to run an AJAX query before the form submit. The query checks how many records are there in the category. After check it fills one of the form field with the received number+1. I'd like to place the code in my submission form template. I have no idea how to solve this. If anybody can help please show me step by step guide.

Thanks in advance.

Last Modified: 02 Oct 2014


Sergey
Total posts: 13,748
18 Sep 2014 09:44

hard to suggect anything without knowing your background. Do you know PHP? Can you handle SQL request to the DB yourself?


danielbidala VIP
Total posts: 153
18 Sep 2014 11:30

Hi Sergey!Thanks for dealing my problem.

Now I use an sql query in my form template php to get the amount of records in the category and than add +1 to it ($sorszam). One of my fields get this value. I use composite title and it's value is based on this field.

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);                             
$query->select('COUNT(*)');

$query->from($db->quoteName('#__js_res_record'));
$query->where($db->quoteName('type_id')." = 1" );
$db->setQuery($query);
$amount = $db->loadResult();
$sorszam = $amount+1;

My problem is that if more than one people try to submit record at the same time there will be duplicated titles because the title is computed at form entry. To solve this I'd like to run the query and add value to my field before submit.


Sergey
Total posts: 13,748
19 Sep 2014 01:26

Then you have to create plugin onBeforeArticleSaveв event

http://docs.mintjoomla.com/en/cobalt/cobalt-events/


danielbidala VIP
Total posts: 153
21 Sep 2014 12:29

Thanks but I can't build the query inside plugin my php and ajax knowledge is poor.


Sergey
Total posts: 13,748
22 Sep 2014 01:56

I only can recommend you comething like linda.com to learn or getafreelancer.com to hire in this case.


danielbidala VIP
Total posts: 153
29 Sep 2014 12:09

Sergey!

Do you have any other idea to my problem. I don't insist to the solution above. In your opinion is there any other solution to add individual title to records based on number of pieces (number of records)? Or do you undertake this for additional money?


Sergey
Total posts: 13,748
01 Oct 2014 02:24

So you need sequential number in the title? Can you tell me more why number have to be sequential? How important it is that it is series of numbers and not simply random generated code like S45DF, 20J45, ...?


danielbidala VIP
Total posts: 153
01 Oct 2014 12:40

Sorry but yes, I need sequential number because in this section there are orders and this way it is more transparent for my colleagues and clients. Random generated codes are not too communicative.


Sergey
Total posts: 13,748
02 Oct 2014 01:02

But you also have a date right. This may give a clean explanation on order. Look PayPal uses rand.

Powered by Cobalt