× Form Help

Edit options in Drop Down List

  • ante
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 37
  • Thank you received: 0

ante created the topic: Edit options in Drop Down List

Hello

I have a delicate problem.

So far I have created a simple form containing some Drop Down Menues. The options in one of these drop downs (say "ddm3") should be editable by a user with higher permission and then normal users should be able to chose between whatever is in the list.

I was thinking of using Contentbuilder to help with this. In Data Storages I chose to use an existing table "XX_facileforms_elements", and then I fooled around a bit with the Views without reaching any success.

The thought is to have a page where the privileged user can go and see all options in this specific dropdown and then ADD or Delete options. This should then be reflected in the actual form.

I know I probably need to use this when loading the form, but I do not think it actually covers all of what I need.
crosstec.org/en/support/online-documenta...ct-list-from-db.html

Hope I made myself clear. Is this achievable?

Many thanks in advance :-)

Best,
Ante
#232268
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Edit options in Drop Down List

Hello,

What you want to do is achievable, but it requires putting quite a lot of custom scripts.

Follow this steps to do what you want:
1) In that simple form containing some select list elements you have to create textfield for each option in that specific select list to which you want to be editable.
Name the "Textfield" elements like this "option1", "option2", "option3" etc.
Also, keep in mind that since you want the user to be able to add more options, you have to create as many fields as you might think will be options in the end.

2) Go to Advanced properties of that "ddm3" select list that you want to be editable and in Initscript section set Type to Custom and check the Form Entry checkbox.
In the code area below put the following code:
function ff_ddm3_init(element, condition)
{
    opts = ff_getElementByName("ddm3");
       for (var o = 0; o < opts.length; o++) {
          var i = Number(o)+1; 
           ff_getElementByName('option'+i).value = opts[o].value; 
       }
} // ff_ddm3_init
NOTE: The code above will work only if the Name of that select list element is exactly "ddm3".

3) Go to Advanced properties of first textfield that you have created named "option1" and in Actionscript section set Type to Custom and check the Change checkbox.
Then in the code area below put the following code:
function ff_option1_action(element, action)
{
    jQuery('#ff_elem27089').empty();

     for (var i = 1; i <=  5; i++) { 
              if( ff_getElementByName('option'+i).value != '') {
                  jQuery('#ff_elem27089').append(jQuery('<option>', {
                                value: ff_getElementByName('option'+i).value,
                                text: ff_getElementByName('option'+i).value
                            })); 
                        }
                  }
} // ff_option1_action
NOTE: In the code above you have to replace ff_elem27089 with the ID of the ddm3 select list. You can get the Id by Inspectiong the element.

4) Repeat the process from the step 3) for each textfield that you have created. Copy the script and only replace option1 with option2, option3 etc. depending on what is the Name of the element to which you are adding Actionscript.

5) Go to form's Advanced properties > More options > Submit pieces and in End Submit section set Type to Custom.
In the code area below put the following code:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

for ($i = 0; $i <= 5; $i++) {
    if( ff_getSubmit('option' . $i) != '' ) { 
     $test .= "0;".ff_getSubmit('option' . $i).";".ff_getSubmit('option' . $i) ."\n";
     }
}

$db->setQuery("UPDATE #__facileforms_elements SET data2 = '$test' WHERE id = 27089"); 
$db->execute();
NOTE: In the code above replace 5 with the number of textfields for options that you have created.
Furthermore, replace 27089 with the if of the ddm3 select list element in #__facileforms_elements table in database. You can also find this number in the Id when inspecting the element.

That will do the trick, user will be able to edit/delete/add options in textfields "option1", "option2" etc. which will then be applied to the select list.

Regarding the part that only some users should be able to do this, you should create two ContentBuilder Views based on this form as explained here crosstec.org/en/support/online-documenta...rms-integration.html . Don't do it as you've tried (In Data Storages I chose to use an existing table "XX_facileforms_elements", and then I fooled around a bit with the Views without reaching any success.).

In the view for privileged users you would include all elements and make them editable, and in the view for other users you wouldn't.

I'm sending you an example form so you can see how it works. Unzip it and Install the xml file as explained here crosstec.org/en/support/online-documenta...ted/94-packages.html .
The form wont' work until you adjust the ID of ddm3 select list in all of the actionscripts and End Submit piece.

Let me know whether this helped and whether you have managed to set this for your form.

Regards,

Mihaela
#232338
Attachments:
  • ante
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 37
  • Thank you received: 0

ante replied the topic: Edit options in Drop Down List

Thanks a lot Mihaela.

I will try this within the next days. But I know your solutions works :)

From what I understand this solution gives me a few concerns since the select list currently holds 50+ options and values and privileged user should be able to add as many as they want or delete. To make it a bit more harder, the Option (Visible in the select list) should be the same as the value. So if user inputs "campaign_name_a1" the whole string should look "0;campaign_name_a1;campaign_name_a1" (and the input could be anything).

1. My original thought was to have one page apart from the form where the content of column "data2" in database table "_facileforms_elements" should be presented in an editable textarea. After edit user saves and the database table is saved with edited stuff.

2. Optionally to make a fusion between the above (1) and your suggested solution. On privileged user page, If all current options/values in column "data2" in database table "_facileforms_elements" are presented in a table, one row each.
For each row the user have the opportunity to delete or edit the row. At the bottom of the table there is a button "Add new row", upon pressing this a new text area is created in where the user enters inputs the new value "0;campaign_name_a1;campaign_name_a1" (or even better only "campaign_name_a1" for us to create the full string with code). When the user then click the save button, the new row will append what is already in the "data2" column.

Is any of these achievable? Preferable option 2

Super grateful for your support.

Best regards,
Ante
#232358
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Edit options in Drop Down List

Hello again,

Using a textarea to set select-list values is a great idea. It will make things simpler, that idea didn't cross my mind before.

Ti use this solution "For each row the user have the opportunity to delete or edit the row. At the bottom of the table there is a button "Add new row", upon pressing this a new text area is created in where the user enters inputs the new value "0;campaign_name_a1;campaign_name_a1" " you would once again need to have as many textfields as options in a list would be so that isn't acceptable solution for you.

The idea from 1. can be done. It can also be improved in a way that user doesn't have to enter "0;campaign_name_a1;campaign_name_a1" and can only enter this "campaign_name_a1".
The only condition is that he has to put each option in new line in the textarea.

Follow this steps to achieve what you want:

1) Create a new form with textfield named "options".

2) Go to form's Advanced properties > More options > Form pieces and in Before Form section set Type to Custom.
In the code area below put the following code:
$this->execPieceByName('ff_InitLib'); //Include BreezingForms Library
$db = JFactory::getDBO();//Get Database Object

$db->setQuery("SELECT data2 from #__facileforms_elements WHERE id = 27179"); 
$test = $db->loadResult();

$opts = "";

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


function getBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
        $r = explode($end, $r[1]);
        return $r[0];
    }
    return '';
}

ff_setValue('options', $opts);
NOTE: In the code above replace 27179 with the id of the ddm3 select list element in #__facileforms_elements table in database.

3) Go to form's Advanced properties > More options > Submit pieces and in End Submit section set Type to Custom.
In the code area below put the following code:
$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 = 27179"); 
$db->execute();
NOTE: Once again in the code above replace 27179 with the id of the ddm3 select list element in #__facileforms_elements table in database.

You can have this as a separate form to which only that specific group of users will have access to.
Also, you could add the textfield to the original form if you want the editor of the select-list to see other fields, but then you just have to create two separate views as explained.

Let me know whether this solution is what you were looking for.
If you have more questions, feel free to ask.

Regards,

Mihaela
#232372
  • ante
  • Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 37
  • Thank you received: 0

ante replied the topic: Edit options in Drop Down List

Hello Mihaela

Needless to say, but this worked as a charm. Many thanks. (Used TeaxtArea instead of TextField).

Two more request to this that I believe need a piece of code. (If not to much asked)

If I remove a line in the middle of the list and Update to the database, I get a gap upon saving. This gap is then also available in the drop down. Off-course user can delete the empty row themselves when editing, but to prevent the human mind from failure... is there anything that can be done with a piece of code?

Also is it possible to make sure the top value is not edited or deleted? It currently says "Pick a Campaign", and is default. Would like to prevent anything to go wrong with this one.

If the solutions are to hard, I am more than happy to instruct the user to manually make sure all is in order.

Again, thanks a lot. You are awesome.

Best,
Ante
#232413
Attachments:
  • Posts: 1465
  • Karma: 48
  • Thank you received: 194

mihaela replied the topic: Edit options in Drop Down List

Hello again,

I'm glad I've helped and that you have managed to apply it to your form to work properly.

Regarding the gap in the select list in case in textarea an empty row is present, here is how that can be prevented.
In End Submit pieces, after this line of code:
$test = ff_getSubmit('options');
this function should be added:
$test = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $test);
It will remove the empty lines from text submitted in the textarea.

Here are also instructions on how to make sure that top option "Pick a Campaign" isn't edited or deleted.
The trick will be that this option won't even appear in the textarea, but it will be added by a bit of coding.

Follow these steps to achieve what you want:
1) Firstly, in End Submit pieces, replace this line of code:
$opts = "0;Pick a Campaign;\n";
with this code:
$opts = "0;Pick a Campaign;\n";
That will add the "Pick a Campaign" option to select list before saving new options to database.

2) Secondly, in Before Form pieces code replace this part of code:
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    $output = "";
    $output = getBetween($line, ';', ';');
   $opts.= $output."\n";
} 
with this one:
$tmp = 0;
foreach(preg_split("/((\r?\n)|(\r\n?))/", $test) as $line){
    if( $tmp != "0") {
       $output = "";
       $output = getBetween($line, ';', ';');
       $opts.= $output."\n"; }
   $tmp = $tmp + 1;
} 
What this will do is that it will avoid copying the first option "Pick a Campaign" from database to the textarea.

NOTE: If at the moment "Pick a Campaign" isn't the first options, it will erase whatever the first option is. But, after you submit the form once you are sure that no option other than "Pick a Campaign" will be erased.

Let me know whether this helped and whether it works as you wanted.

Regards,

Mihaela
#232427
Moderators: ForumSupporttomeperica
Time to create page: 0.080 seconds

New Support System

Dear Customers,

Users with active subscription have support priority which will be dona via ServiceDesk (My Account > Raise a ticket).
FREE Support topics will be answered when AND if there is time.

You can check support guidelines here : here

Regards,
Crosstec 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

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