× Form Help

Edit options in Drop Down List

  • ante
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 61
  • Thank you received: 0

ante replied the topic: Edit options in Drop Down List

Hello

Picking up this topic again.

The solution suggested earlier works perfectly. But I have found a disturbing and kind of major issue.

Whenever in the backend when saving a form under Manage Forms All the options in the Drop Down Select List returns to default. That is they return to the options available in the Element configuration for this drop down list. This is most likely because the new options added to the select list in the frontend, is not added to the backend.

Could this be fixed?

Best regards,
Ante
#234287
  • Posts: 3128
  • Karma: 105
  • Thank you received: 411

mihaela replied the topic: Edit options in Drop Down List

Hello,

You are right. When the form is saved in Manage forms it collects data which is entered in "List" field in properties of the Select list element in the form. Therefore you see the options that were initially set in that field (refreshes value in data2 in database).

Then when you enter the form with the textfiled for editing, the Textarea gets updated with values from data2 and you see there the new options too.

Because of that, if you intend on making changes to the form and saving it, this requires a new approach.

The code form End Submit pieces from the form that contains Textarea should be take to Before Form pieces in the form that contains select list.
This is the code that I am talking about:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$test = ff_getSubmit('options');
$opts = "";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    $opts.= "0;". $line .";". $line ."\n";
} 

$db->setQuery("UPDATE #__facileforms_elements SET data2 = '$opts' WHERE id = 244"); 
$db->execute();
Now, since you can't use "ff_getSubmit('options')" anymore, instead of setting the value of variable test like this:
$test = ff_getSubmit('options');
you need to write the query to get the value from last submission from "#__facileforms_subrecords" table.

Furthermore, you need to adjust the code in Before Form pieces so that instead of collecting data from column data2 in #__facileforms_elements that it also collects data from the last submission of element "options" in "#__facileforms_subrecords" table.

This will make the code much simpler since this value that you get you won't need to modify, so the whole code will look like:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$db->setQuery("YOUR QUERY HERE"); 
$test = $db->loadResult();

ff_setValue('options', $test);

Let me know whether you have managed to make it work.

Regards,

Mihaela
#234352
  • ante
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 61
  • Thank you received: 0

ante replied the topic: Edit options in Drop Down List

Hello Mihaela
Thanks for your reply.

I am a bit confused, since I also have some other rows that you helped me with to; trim line, replace blanks...

My code in End Submit currently looks like this:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$test = ff_getSubmit('campaignoptions');
$test = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $test);

$opts = "0;Pick a Campaign;\n";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    $line = trim($line);
    $line = str_replace(' ', '_', $line);
    $opts.= "0;". $line .";". $line ."\n";
}

$db->setQuery("UPDATE #__facileforms_elements SET data2 = '$opts' WHERE id = 18"); 
$db->execute();

Possible to fit that in?

Also, do you mean that I should keep both Queries old "facileforms_elements" and the new "facileforms_subrecords" or just the new subrecords?

The query curently looks like this:
$db->setQuery("UPDATE #__facileforms_elements SET data2 = '$opts' WHERE id = 18"); 
Based on the attached screensump, Should the new one be:
$db->setQuery("GET#__facileforms_subrecords SET value = '$opts' WHERE element = 18"); 

I am a bit suspicious to my line above since in your new solution you have not used '$opts', is "element" correct column to use based on the screendump if I want to use the element called CampaignName, and finally am I supposed to use "GET" instead of "UPDATE"
Or perhaps I just skip the SET value part and do:
$db->setQuery("GET#__facileforms_subrecords WHERE element = 18"); 

Sorry for overwhelming you with all my thoughts and questions.

Best regards,
Ante
#234438
Attachments:
  • Posts: 3128
  • Karma: 105
  • Thank you received: 411

mihaela replied the topic: Edit options in Drop Down List

Hello again,

Here is the complete code that will make this work as you wanted and after the form is saved the select list won't return to starting state.

First go to the form that contains the "options" select list.

In Before Form pieces put the following code:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$db->setQuery("SELECT value from #__facileforms_subrecords WHERE element = 254 ORDER BY id DESC "); 
$test = $db->loadResult();

ff_setValue('options', $test);
NOTE: In the code above replace 254 with the ID of that textarea element (look in #__facileforms_subrecords fin element column for this number). Also, replace 'options' with the Name of the textarea element.

In End Submit pieces put this piece of code:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$test = ff_getSubmit('options');
$test = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $test);

$opts = "";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    $line = trim($line);
    $line = str_replace(' ', '_', $line);
    $opts.= $line ."\n";
}


$db->setQuery("UPDATE #__facileforms_subrecords SET value ='$opts' WHERE element = 254 AND record = (Select Max(id) From #__facileforms_records Where name = 'QuickForm525934685') "); 
$db->execute();
NOTE: In code above replace QuickForm525934685 with the name of your form. Also, replace 254 with the ID of that textarea element (look in #__facileforms_subrecords fin element column for this number).
Finally, replace 'options' with the Name of the textarea element.

Now go to the form which contains the select list element.
In Before form pieces put the following code:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$db->setQuery("SELECT value from #__facileforms_subrecords WHERE element = 254 ORDER BY id DESC "); 
$test = $db->loadResult();

$opts = "";
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    $opts.= "0;". $line .";". $line ."\n";
}

function ff_setSelectList($name, $value)
{
     global $ff_processor;
     for ($r = 0; $r < $ff_processor->rowcount; $r++)
     {
          $row =& $ff_processor->rows[$r];
          if ($row->name==$name)
          $row->data2 = $value;
          unset($row);
     } // for
} // ff_setSelectList

ff_setSelectList('selectlist', $opts);
NOTE: In the code above once again replace 254 with the ID of that textarea element. Also, replace selectlist with the name of the select list in your form.

Regards,

Mihaela
#234457
  • ante
  • Topic Author
  • Offline
  • Senior Boarder
  • Senior Boarder
  • Posts: 61
  • Thank you received: 0

ante replied the topic: Edit options in Drop Down List

Mihaela... don't know what to say. It works and you are great.

There is one more (think small) issue that appear now, which worked earlier.
At the end of page one in this thread and start of page two, you fixed so that the first line in the drop down list would always be "0;Pick a Campaign;" no matter if super user mistakenly deleted it form the editable textArea. This does not work now. It was easy to identify the first part of the solution where I should replace to be
$opts = "0;Pick a Campaign;\n";
in the end submit.
But when looking at the rest, the code seem very different now I believe.

Best,
Ante
#234473
  • Posts: 3128
  • Karma: 105
  • Thank you received: 411

mihaela replied the topic: Edit options in Drop Down List

Hello Ante,

Thank you for the kind words. :)

Since the option
"0;Pick a Campaign;"
isn't needed to be present in textarea, you can just add it in Before Form pieces of the form that contains Select list element.

Just replace this line of code:
$opts = "";
with this one:
$opts = "0;Choose option;\n";

Let me know whether it works as you wanted.

Regards,

Mihaela
#234485
Moderators: ForumSupporttomeperica
Time to create page: 0.236 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription 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 for just 49! (Summer Sale)

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!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

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