BF as query to MySQL

  • GalanopD
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 22
  • Thank you received: 1

GalanopD created the topic: BF as query to MySQL

Hi! I have created a BF (called membersearch) with some fields (selectlist, text,etc). So what I need is when the user fills out the form and clicks the "Save" button (in my case "Search"), the form to use the input of the user as a query to search the MySQL database and post results below the form on my php page without refreshing the page. I have to mention that another BF (called memberapplication) is used to store data to MySQL (#_facileforms_subrecords) and that is where I want the BF (called membersearch) to look and get the data to post. I have been searching this forum for this but without success. Is there any previous post on how to use a BF as jquery to MySQL and post data on the page?

Thank you
#231627
  • Posts: 2154
  • Karma: 67
  • Thank you received: 263

DarkoCujic replied the topic: BF as query to MySQL

Hey,

so, you're using the form as a "search" form. So there's no actual submitting or anything like that? How are you publishing the form? What does "below the form" mean? If I understood everything, it's not that difficult, but you do have to have some coding knowledge to put it all together.

I'd do it like this. Publish the form in a module somewhere on the page and below that module add another module that would only contain the following as the code:
<div id="frmSrchResults"></div>
That will be a placeholder for the results.

Then, add an ActionScript to your button that does the querying and simply use jQuery (or JavaScript) to change the html() (or innerHTML) of that div#frmSrchResults. You have to do a jQuery.post(). The code would look something like this:
// actionscript code - don't forget to check 'click' and click Create Code Framework to give you a skeleton, so you add your code in the created function
// this is only the part that goes in the function

// get all the needed values from the form. I've added just two since I don't know how it looks like
let var1 = ff_getElementByName('field-of-first-search-parameter').value;
let var2 = ff_getElementByName('field-of-second-search-parameter').value;

// call the .post
jQuery.post(
  '<?php return JUri::root(); ?>index.php', {
    option: 'com_breezingforms',
    ff_form: ff_processor.form,
    format: 'html',
    par1: var1,
    par2: var2
  },
  function(data) {
    jQuery('#frmSrchResults').html(data);
  }
);

From the code, you can see you posted on the form itself, so now we have to add a Before Form piece to handle that POST request. So, add a custom Before Form piece with the following code:
$this->execPieceByName('ff_InitLib');

// fetch .post() parameters
$var1 = JRequest::getVar('par1');
$var2 = JRequest::getVar('par2');

if ($var1 && $var2 && $var1 !== '' && $var2 !== '') {
  $db = JFactory::getDBO();
  $db->setQuery("do whatever needs to be done in the query");
  $result = $db->loadAssocList();
  
// clean output buffer
  while (@ob_get_level() > 0) { @ob_end_clean(); }

// here you can add some algorithm to style everything the way it has to be
// simply start a new variable (empty one) and add everything inside
  echo $result;
  exit;
}

There's a lot of topics that cover what you need, so I'll just put some links here. They all do a query on the database, the only difference is what they're doing inside the success function.

crosstec.org/en/forums/3-breezingforms-f...html?start=12#220484
crosstec.org/en/forums/1-forums/112909-l....html?start=6#219434
crosstec.org/en/forums/3-breezingforms-f...html?start=12#218261
crosstec.org/en/forums/3-breezingforms-f...que-data.html#202566
crosstec.org/en/forums/3-breezingforms-f....html?start=6#195703
...

Regards,
Darko

Satisfied with our support? PayPal tips
===========
Need to renew Pro Support? Buy Here!
===========
Satisfied? Consider a membership!
===========
Like us on Facebook
===========
Support Crosstec and get ALL EXTENSIONS and professional support for just $5. Here!
#231658
  • GalanopD
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 22
  • Thank you received: 1

GalanopD replied the topic: BF as query to MySQL

Dear Darko,

First of all thank you very much! I appreciate your effort to help.
1. You say: "So there's no actual submitting or anything like that?".
Answer: I have created membersearch form and posted on my webpage. If I am not mistaken when we create a BF it is automatically connected to the database. No? Maybe I am wrong...
2. You say: " How are you publishing the form?"
Answer: I am not sure I understand this question but I think that you mean where it is published? It is published on my index.php page. My website is joomla.
3. You say: "What does "below the form" mean?"
Answer: You understood correctly as you describe further down!

I will try to implement all the steps that you describe and see the results later on today or tomorrow and then give you some feedback.

Once again, thanks a lot!
Dimitris
#231664
  • Posts: 2154
  • Karma: 67
  • Thank you received: 263

DarkoCujic replied the topic: BF as query to MySQL

Hey,

yes, all forms are connected to the database. But, in this "search" form, you have no actual submitting. As in, it's not collecting any data. It's just for querying the database?

For the second question, are you publishing the form inside a module, as a menu item or through a plugin (content inside an article)?

Anyways, it's not even that important to answer these questions, as the workflow is pretty much the same for everything. Implement it and consult with the topics I linked in my previous post. All the needed info should be in those topics.

Regards,
Darko

Satisfied with our support? PayPal tips
===========
Need to renew Pro Support? Buy Here!
===========
Satisfied? Consider a membership!
===========
Like us on Facebook
===========
Support Crosstec and get ALL EXTENSIONS and professional support for just $5. Here!
#231665
  • GalanopD
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 22
  • Thank you received: 1

GalanopD replied the topic: BF as query to MySQL

Hi Darko,

Here is what I have included in the Search button but I have definitely done something wrong as the button is not shown properly and the form "misbehaves". What do you mean by "do whatever needs to be done in the query" further down?:

function ff_bfQuickMode942192_action(element, action)
{
let var1 = ff_getElementByName('capabilities').value;
let var2 = ff_getElementByName('membershiptype').value;
// call the .post
jQuery.post(
'<?php return JUri::root(); ?>index.php', {
option: 'com_breezingforms',
ff_form: ff_processor.form,
format: 'html',
par1: var1,
par2: var2
},
function(data) {
jQuery('#frmSrchResults').html(data);
}
);
switch (action) {
case 'click':
break;
default:;
} // switch
} // ff_bfQuickMode942192_action


Also, is this what I put in the before piece of the form? And if yes, can you please explain what do you mean by "//Create your own query here"?

$this->execPieceByName('ff_InitLib');

// fetch .post() parameters
$var1 = JRequest::getVar('par1');
$var2 = JRequest::getVar('par2');

if ($var1 && $var2 && $var1 !== '' && $var2 !== '') {
$db = JFactory::getDBO();
$db->setQuery("do whatever needs to be done in the query");
$result = $db->loadAssocList();

// clean output buffer
while (@ob_get_level() > 0) { @ob_end_clean(); }

// here you can add some algorithm to style everything the way it has to be
// simply start a new variable (empty one) and add everything inside
echo $result;
exit;
}
Thank you Darko
#231674
  • Posts: 2154
  • Karma: 67
  • Thank you received: 263

DarkoCujic replied the topic: BF as query to MySQL

Hey,

I don't know what you want to query for. I can't write the query for you unfortunately.

The "main" record is stored in #__facileforms_records and all the values from that record are stored in #__facileforms_subrecords. So, I'm guessing you're going to have to query through #__facileforms_subrecords where value=$var1 and value=$var2. And join that with the records table to get record id and pull info from that record or something like that.

A standard query to get, for example, everything from the records table would be:
Select * From #__facileforms_records

Please look up some MySQL tutorials on how to write queries.

Regards,
Darko

Satisfied with our support? PayPal tips
===========
Need to renew Pro Support? Buy Here!
===========
Satisfied? Consider a membership!
===========
Like us on Facebook
===========
Support Crosstec and get ALL EXTENSIONS and professional support for just $5. Here!
#231682
Moderators: ForumSupporttomeperica
Time to create page: 0.039 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99€

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here