Buy Now
Sign in

CFv5: Sum up different values to aricle number in textbox before submitting

sub_mar , August 19 2019, 07:27
S
sub_mar 10
August 19 2019, 07:27 #388901
Hello,

I have the following problem in Chronoforms v5:
A product is to be configured in a form. Different values can be selected via dropdown or radio box:

Selection A:
A1
A2

Selection B:
B1
B2

Selection C:
C1
C2

Selection D:
D1
D2
D3
D4

A text box should summarize the values to an article number - before the form is sent - and show them in a text box. Ideally without an additional database deposit.

The article number can be composed of the individual values (e.g. A1=222, B2=555, C1=888, D3=777 becomes 222-555-888-777). Or the article number can be adjusted by using a table (e.g. A1 |B2 |C1 |D3 | 222-555-888-777).

Is this possible?
GreyHead 64
August 19 2019, 08:11 #388902
Hi sub_mar,
Yes, it's possible. You need to use Custom JavaScript to combine the strings into an article number. That is probably simplest if you can set the 222 strings as values in the drop-downs.
You can display the article number in a read only text input. That will submit with the form data BUT you should check the value using PHP after submission as JavaScript in the browser is always open to 'user interference'.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
sub_mar 10
August 19 2019, 08:16 #388904
Hi GreyHead,

thank you for the quick reply!

Could you please help me with the coding? I am a totally beginner with JavaScript an PHP.
sub_mar
GreyHead 64
August 19 2019, 09:20 #388917
Hi sub_mar,
I can't help you right away, my main internet was taken out in a thunderstorm and I'm working through my phone which is not a good coding environment. If you want to send me the details in a PM I can look when my connection is fixed.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
sub_mar 10
August 19 2019, 10:42 #388918
unfortunately I can't send any PMs yet, so here's the form in HTML (anonymous):
<div class="chronoform-container" id="chronoform-container-275" style="overflow:auto;">
<div class="chronoform-container" id="chronoform-container-276" style="float:left; width:74%">
<div class="colora" id="colora" data-load-state="hidden">
<h4>Model ColorA</h4>
<img alt="ColorA" src="http://placekitten.com/1600/400">
</div>
<div class="colorb" id="colorb" data-load-state="hidden">
<h4>Model ColorB</h4>
<img alt="ColorA" src="http://placekitten.com/1600/450">
</div>
</div>
<div class="chronoform-container" id="chronoform-container-277" style="float:left; width:24%">
<h4>Things</h4>
<h5>First</h5>
<div class="gcore-input-wide gcore-display-table" id="fin-absehen">
<div class="gcore-single-column" id="fclmn">
<div class="gcore-radio-item form-absehen-left" id="fitem">
<label class="control-label gcore-label-checkbox" for="absehen">
<input name="absehen" title="" class="auswahl-absehen A" id="absehen" style="" type="radio" value="415-" data-load-state="" data-tooltip="">
ThingD<br />
<img alt="ThingD" src="http://placekitten.com/190/190" />
</label>
</div>
<div class="gcore-radio-item form-absehen-right" id="fitem1">
<label class="control-label gcore-label-checkbox" for="absehen1">
<input name="absehen" title="" class="auswahl-absehen A" id="absehen1" style="" type="radio" value="131-" data-load-state="" data-tooltip="">
ThingC<br />
<img alt="ThingC" src="http://placekitten.com/190/190" />
</label>
</div>
<div class="gcore-radio-item form-absehen-left" id="fitem2">
<label class="control-label gcore-label-checkbox" for="absehen2">
<input name="absehen" title="" class="auswahl-absehen A" id="absehen2" style="" type="radio" value="112-" data-load-state="" data-tooltip="">
ThingB<br />
<img alt="ThingB" src="http://placekitten.com/190/190" />
</label>
</div>
<div class="gcore-radio-item form-absehen-right" id="fitem3" >
<label class="control-label gcore-label-checkbox" for="absehen3">
<input name="absehen" title="" class="auswahl-absehen A" id="absehen3" style="" type="radio" value="101-" data-load-state="" data-tooltip="">
ThingA<br />
<img alt="ThingA" src="http://placekitten.com/190/190" />
</label>
</div>
</div>
</div>
</div>
</div>
<div style="clear:both;"></div>
<div class="chronoform-container" id="chronoform-container-329" style="overflow:auto;">
<div class="chronoform-container" id="chronoform-container-330" style="float:left; width:32%">
<div class="form-group gcore-form-row" id="form-row-tuerme">
<label for="tuerme" class="control-label gcore-label-left">
Part
</label>
<div class="gcore-input gcore-display-table" id="fin-tuerme">
<select name="tuerme" id="tuerme" size="" class="form-control A" title="" style="" data-load-state="" data-tooltip="">
<option value="161">PartA</option>
<option value="718">PartB</option>
</select>
</div>
</div>
<div class="parta" id="parta" data-load-state="hidden">
<img alt="PartA" src="http://placekitten.com/400/300">
</div>
<div class="partb" id="partb" data-load-state="hidden">
<img alt="PartB" src="http://placekitten.com/450/300">
</div>
</div>
<div class="chronoform-container" id="chronoform-container-366" style="float:left; width:32%">
<div class="form-group gcore-form-row" id="form-row-farbe">
<label for="farbe" class="control-label gcore-label-top">
Color
</label>
<div class="gcore-input-wide gcore-display-table" id="fin-farbe">
<select name="farbe" id="farbe" size="" class="form-control A" title="" style="" data-load-state="" data-tooltip="">
<option value="456-">ColorA</option>
<option value="789-">ColorB</option>
</select>
</div>
</div>
<div class="form-group gcore-form-row" id="form-row-anzahl">
<label for="anzahl" class="control-label gcore-label-top">
Quantity
</label>
<div class="gcore-input-wide gcore-display-table" id="fin-anzahl">
<input name="anzahl" id="anzahl" value="" placeholder="" class="validate[&#039;number&#039;] form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" />
</div>
</div>
</div>
<div class="chronoform-container" id="chronoform-container-347" style="float:left; width:32%">
<div class="form-group gcore-form-row" id="form-row-artikelnummer">
<label for="artikelnummer" class="control-label gcore-label-top">
Article Number
</label>
<div class="gcore-input-wide gcore-display-table" id="fin-artikelnummer">
<input name="artikelnummer" id="artikelnummer" value="" placeholder="" class="form-control A" title="" style="" data-inputmask="" data-load-state="" data-tooltip="" type="text" />
</div>
</div>
<div class="form-group gcore-form-row" id="form-row-sonstiges">
<label for="sonstiges" class="control-label gcore-label-top">
Others:
</label>
<div class="gcore-input-wide gcore-display-table" id="fin-sonstiges">
<textarea name="sonstiges" id="sonstiges" placeholder="" rows="3" cols="40" class="form-control A" title="" style="" data-wysiwyg="0" data-load-state="" data-tooltip=""></textarea>
</div>
</div>
</div>
</div>
The configured article contains 123- (=Model) in every way and the Customer can't choose it anywere.

The Order for the article number is: Model + Color + Thing + Part
do you need other information
S
sub_mar 10
August 19 2019, 10:44 #388919
Edit: the article number should actually appear in the text box article number.
S
sub_mar 10
August 23 2019, 10:55 #388963
<div>Hi Bob,<br><br>I now have a script that will definitely work local. I already tested it.</div><div>​</div><pre class="ui message cfu-code" style="overflow:auto; border:none;"><script><br> function fillTextBox() {<br> var txt = '123-';<br> txt += document.getElementById("farbe").value;<br> <br> var ele = document.getElementsByName('absehen'); <br> <br> for(i = 0; i < ele.length; i++) { <br> if(ele[i].checked) <br> txt += ele[i].value;; <br> } <br> txt += document.getElementById("tuerme").value;<br> document.getElementById('artikelnummer').value=txt;<br> };<br></script></pre><div>​</div><div>I have to insert the script snippet into an OnLoad event, I already found out that much (source: https://www.chronoengine.com/faqs/54-chronoforms/cfv4/cfv4-validation/2597-how-can-i-add-javascript-to-my-form).<br><br>However, none of the specified variants work:<br></div><pre class="ui message cfu-code" style="overflow:auto; border:none;">function fillTextBox() {<br> var txt = '123-';<br> txt += document.getElementById("farbe").value;<br> <br> var ele = document.getElementsByName('absehen'); <br> <br> for(i = 0; i < ele.length; i++) { <br> if(ele[i].checked) <br> txt += ele[i].value;; <br> } <br> txt += document.getElementById("tuerme").value;<br> document.getElementById('artikelnummer').value=txt;<br> };</pre><div>​</div><div>or</div><div>​</div><pre class="ui message cfu-code" style="overflow:auto; border:none;">window.addEvent('domready', function() {<br> <br><br> function fillTextBox() {<br> var txt = '123-';<br> txt += document.getElementById("farbe").value;<br> <br> var ele = document.getElementsByName('absehen'); <br> <br> for(i = 0; i < ele.length; i++) { <br> if(ele[i].checked) <br> txt += ele[i].value;; <br> } <br> txt += document.getElementById("tuerme").value;<br> document.getElementById('artikelnummer').value=txt;<br> };<br><br><br>});</pre><div>​</div><div>or</div><div>​</div><pre class="ui message cfu-code" style="overflow:auto; border:none;"><?php<br>$script = "<br> <br><br> function fillTextBox() {<br> var txt = '123-';<br> txt += document.getElementById("farbe").value;<br> <br> var ele = document.getElementsByName('absehen'); <br> <br> for(i = 0; i < ele.length; i++) { <br> if(ele[i].checked) <br> txt += ele[i].value;; <br> } <br> txt += document.getElementById("tuerme").value;<br> document.getElementById(artikelnummer').value=txt;<br> };<br><br><br>";<br>$doc =& JFactory::getDocument();<br>$doc->addScriptDeclaration($script);<br>?></pre><div>​</div><div>What am I doing wrong?<br><br>sub_mar</div>
GreyHead 64
August 24 2019, 07:55 #388968
 Answer
Hi sub_mar,
You can load the JavaScript using a Custom JS action in the form On Load event (before the HTML render form action).
You then need to call the function which you can do from the Events tabs of the input elements using the On Change event.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
sub_mar 10
August 26 2019, 15:11 #388989
Hi Bob,
thank you so much for your help. It works now
Have a nice day!
sub_mar
S
sub_mar 10
September 03 2019, 13:48 #389094
Hi Bob,
Okay, I have another problem:

My form now runs like a configurator. If I select a drop-down, an image (hidden div) will be shown. I solved this with the events "show and hide".

In addition there is the working javascript, which merges all selections in a textbox. Thanks to your help this also works great. Because one post is somehow broken, here again the working script:
<script>
function fillTextBox() {
var txt = '123-';
txt += document.getElementById("farbe").value;

var ele = document.getElementsByName('absehen');

for(i = 0; i < ele.length; i++) {
if(ele[i].checked)
txt += ele[i].value;;
}
txt += document.getElementById("tuerme").value;
document.getElementById('artikelnummer').value=txt;
};
</script>
But now it's desired that the form should be enclosed with a multiplier. So it should be possible to configure several products.
I have already dealt with your FAQ: https://www.chronoengine.com/faqs/70-chronoforms/cfv5/5245-how-can-i-use-the-multiplier-in-cfv5
I created the containers multiplier and multiplier-contents and put the rest of the form there (with multi-columns). Then I created the settings of the multiplier-container as follows:
Replacer: __N__
Counter: 1
Hide first: No (if it is set to Yes, the "hide" and "show" events will not work anymore)
Disable first: No (if it is set to Yes, the "hide" and "show" events no longer work)
Hide buttons: No
Start count: 1
Data path: zf (I'm not sure if I have to put anything here at all, because I'm not uploading anything additionally)
If I save now, the form works normally, but the show and hide functions only change for the first form, even if I use the dropdowns in the second form.
Now I have added __N__ for all form fields and the divs behind the ID and the name, also in the events. After that neither the Javascript works nor the motives change after selecting the dropdowns.

What is the error?
sub_mar
GreyHead 64
September 05 2019, 10:15 #389120
Hi sub_mar,
My guess is that the built-in JavaScript for the Hide and Show events doesn't recognise the _N_ replacer. So you'd need to do this using custom code.
Do you need to have this complex multiplier in one page - could you instead accept the first submission and then re-display the form for the next one? That might be simpler to build and manage.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
S
sub_mar 10
September 05 2019, 10:18 #389121
Hi, Bob,

can you explain to me in more detail how I can implement your second proposal?
sub_mar
S
sub_mar 10
September 05 2019, 12:38 #389125
Hi Bob,
I now understand your second proposal. No, I think our customers didn't want to send us multiple Formulars.

It should be easy to manage for our costumers.
to your guess: I think, that this is the problem, too. But I don't know, how to solve the problem.
Which code should be customized?
sub_mar
GreyHead 64
September 06 2019, 09:27 #389132
Hi sub_mar,
I'm not clear why it is more difficult for your customers to select one item after another - that's a bit like a shopping cart :-(
Please see this FAQ for an example that I think is something like what you want.
Using your browser developer tools and maybe the ChronoForms Debugger output you should be able to see exactly what input names and data are and write your code to match.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much