terminal42 / contao-conditionalformfields

Display form fields conditionally in Contao Open Source CMS
MIT License
18 stars 12 forks source link

Issue with entity encoding #39

Closed Cleanerrr closed 4 years ago

Cleanerrr commented 4 years ago

Hi, I need to set conditions for, one value ($var) from a text field(number) and the second value ($example) from a radio buttons menu(string). I need to check input value $var which has to be between 100 and 1000, and in same time variable $example have to be equal value 'privat'. I wrote in condition filed next: $var >= 100 && $var <= 1000 && $example == 'privat' this isn't working. I tried also: ($var >= 100) && ($var <= 1000) && ($example == 'privat') (($var >= 100) && ($var <= 1000)) && ($example == 'privat')

but still not working. I still have the same error: Uncaught SyntaxError: Unexpected token ';'

I tried also next: ($var >= 100) && ($example == 'privat') and this working normal. But, I need first value in the range from 100 to 1000, not just greater than 100.

What am I doing wrong?

Or it's some bag?

aschempp commented 4 years ago

@richardhj can you have a quick check if you see why this is an issue?

richardhj commented 4 years ago

@Cleanerrr can you post a screenshot of the console in the browser, plus the simplified source code of the page?

Cleanerrr commented 4 years ago

Of course @richardhj Console SS: cond-filed-console

Source code:

<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Kontakt - Home</title>
<base href="http://example.com/">
<meta name="robots" content="index,follow">
<meta name="description" content="">
<meta name="generator" content="Contao Open Source CMS">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" href="assets/css/layout.min.css,responsive.min.css,main.scss-0e449ac1.css"><script src="assets/js/jquery.min.js,haste_plus.min.js,contao-utils-bundle.js,environme...-21d63e04.js"></script><script src="system/modules/conditionalformfields/assets/conditionalformfields.min.js?v=65d54247"></script>
</head>
<body id="top" itemscope itemtype="http://schema.org/WebPage">
<div id="wrapper">
<header id="header">
<div class="inside">
<!-- indexer::stop -->
<nav class="mod_navigation main_nav block" itemscope itemtype="http://schema.org/SiteNavigationElement">
<a href="kontakt.html#skipNavigation1" class="invisible">Navigation überspringen</a>
<ul class="level_1">
<li class="sibling first"><a href="./" title="Startseite" class="sibling first" itemprop="url"><span itemprop="name">Startseite</span></a></li>
<li class="submenu sibling"><a href="ueber-uns.html" title="Über uns" class="submenu sibling" aria-haspopup="true" itemprop="url"><span itemprop="name">Über uns</span></a>
<ul class="level_2">
<li class="submenu first last"><a href="ueber-uns-1.html" title="Über uns-1" class="submenu first last" aria-haspopup="true" itemprop="url"><span itemprop="name">Über uns-1</span></a>
<ul class="level_3">
<li class="submenu first last"><a href="ueber-uns-2.html" title="Über uns-2" class="submenu first last" aria-haspopup="true" itemprop="url"><span itemprop="name">Über uns-2</span></a>
<ul class="level_4">
<li class="first last"><a href="ueber-uns-3.html" title="Über uns-3" class="first last" itemprop="url"><span itemprop="name">Über uns-3</span></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li class="submenu sibling"><a href="shop.html" title="Shop" class="submenu sibling" aria-haspopup="true" itemprop="url"><span itemprop="name">Shop</span></a>
<ul class="level_2">
<li class="first"><a href="cd.html" title="CD" class="first" itemprop="url"><span itemprop="name">CD</span></a></li>
<li><a href="download.html" title="Download" itemprop="url"><span itemprop="name">Download</span></a></li>
<li class="last"><a href="t-shirt.html" title="T-Shirt" class="last" itemprop="url"><span itemprop="name">T-Shirt</span></a></li>
</ul>
</li>
<li class="sibling"><a href="specials.html" title="Specials" class="sibling" itemprop="url"><span itemprop="name">Specials</span></a></li>
<li class="submenu sibling"><a href="product-filter.html" title="Filter" class="submenu sibling" aria-haspopup="true" itemprop="url"><span itemprop="name">Filter</span></a>
<ul class="level_2">
<li class="first"><a href="product-filter.html" title="Product Filter" class="first" itemprop="url"><span itemprop="name">Product</span></a></li>
<li><a href="cumulative.html" title="Cumulative Filter" itemprop="url"><span itemprop="name">Cumulative</span></a></li>
<li class="last"><a href="category.html" title="Category Filter" class="last" itemprop="url"><span itemprop="name">Category</span></a></li>
</ul>
</li>
<li class="sibling"><a href="online-shopping.html" title="Online shopping" class="sibling" itemprop="url"><span itemprop="name">Online shopping</span></a></li>
<li class="active"><strong class="active" itemprop="name">Kontakt</strong></li>
<li class="sibling last"><a href="tarifdetails.html" title="Tarifdetails" class="sibling last" itemprop="url"><span itemprop="name">Tarifdetails</span></a></li>
</ul>
<a id="skipNavigation1" class="invisible">&nbsp;</a>
</nav>
<!-- indexer::continue -->
</div>
</header>
<div id="container">
<main id="main">
<div class="inside">
<div class="mod_article first last block" id="article-3">
<!-- indexer::stop -->
<div class="ce_form first last block">
<form method="post" enctype="application/x-www-form-urlencoded" id="tariffe-calculator">
<div class="formbody">
<input type="hidden" name="FORM_SUBMIT" value="auto_form_2">
<input type="hidden" name="REQUEST_TOKEN" value="1p1eU4Q8_mPC0YAvsrX0CuTmUXC_7JQGkkuAdwtX8Xs">
<div class="widget widget-explanation explanation">
<h2>JETZT GÜNSTIGEN TARIF FINDEN</h2></div>
<div class="widget widget-text">
<input type="text" name="tariffe" id="ctrl_41" class="text" value="" placeholder="5000" minlength="100" maxlength="100000">
</div>
<div class="widget widget-radio mandatory">
<fieldset id="ctrl_17" class="radio_container mandatory">
<span><input type="radio" name="privatgewerbe" id="opt_17_0" class="radio" value="privat" required> <label id="lbl_17_0" for="opt_17_0">privat*</label></span>
<span><input type="radio" name="privatgewerbe" id="opt_17_1" class="radio" value="gewerbe" required> <label id="lbl_17_1" for="opt_17_1">gewerbe*</label></span>
</fieldset>
</div>
<fieldset class="cffs-8">
<div class="widget widget-explanation explanation">
<h2>Privat Tariffe 1</h2>
<p>Unsere Tarif-Empfehlung:</p>
<p>Ihr Preis im ersten Jahr bei Tariffe 1 18.000 kWh Jahresverbrauch in (inkl. Ust.):</p>
<p><strong><span class="copy-blue">747,89 €</span></strong></p>
<p>Ihr Grundpreis:<br><span class="copy-blue">58,49 €/Jahr</span></p>
<p>Ihr Arbeitspreis:<br><span class="copy-blue">3,83 ct/kWh</span></p>
<p><a href="kontakt.html">Tarif abschließen</a></p>
<p><a href="tarifdetails.html"><span class="copy-blue">Tarifdetails</span></a></p>
<p><span class="copy-blue"><a href="javascript:history.go(-1)" title="Zurück">Zurück</a></span></p></div>
</fieldset>
<fieldset class="cffs-18">
<div class="widget widget-explanation explanation">
<h2>Gewerbe Tariffe 1</h2>
<p>Unsere Tarif-Empfehlung:</p>
<p>Ihr Preis im ersten Jahr bei Tariffe 1 18.000 kWh Jahresverbrauch in (inkl. Ust.):</p>
<p><strong><span class="copy-blue">747,89 € </span></strong><strong>&nbsp;&nbsp;</strong></p>
<p>Ihr Grundpreis:<br><span class="copy-blue">58,49 €/Jahr</span></p>
<p>Ihr Arbeitspreis:<br><span class="copy-blue">3,83 ct/kWh</span></p>
<p><a href="kontakt.html">Tarif abschließen</a></p>
<p><a href="tarifdetails.html"><span class="copy-blue">Tarifdetails</span></a></p>
<p><span class="copy-blue"><a href="javascript:history.go(-1)" title="Zurück">Zurück</a></span></p></div>
</fieldset>
</div>
</form>
</div>
<!-- indexer::continue -->
</div>
</div>
</main>
</div>
</div>
<script>(function($){$('input[name="FORM_SUBMIT"][value="auto_form_2"]').parents('form').conditionalFormFields({'fields':["var","example"],'conditions':{"8":"return (values.var >= 100 && values.var &lt;= 1000 && values.example == 'privat');","18":"return (values.var >= 100 && values.var &lt;= 1000 && values.example == 'gewerbe');"}})})(jQuery)</script></body>
</html>
richardhj commented 4 years ago

There is an issue in your snippet:

- (values.var >= 100 && values.var &lt;= 1000 && values.example == 'gewerbe');
+ (values.var >= 100 && values.var <= 1000 && values.example == 'gewerbe');

Is it possible to get rid of the &lt; when you re-type and save the element in the Contao back end? Otherwise, can you make the change via phpMyAdmin?

Cleanerrr commented 4 years ago

In Contao backend, in form, filedset condition, is written: $var >= 100 && $var <= 1000 && $example == 'privat' Is it possible that the problem is the same variable? $var >= 100 && $var <= 1000 Variable var is greater than 100 and var is less than 1000.

Cleanerrr commented 4 years ago

There is an issue in your snippet:

- (values.var >= 100 && values.var &lt;= 1000 && values.example == 'gewerbe');
+ (values.var >= 100 && values.var <= 1000 && values.example == 'gewerbe');

Is it possible to get rid of the &lt; when you re-type and save the element in the Contao back end? Otherwise, can you make the change via phpMyAdmin?

I tried to change this input, but the same problem. When I set only two conditions, haven't the problem, everything work. But when I write third, then I have a problem. Actually, I need input XY variable which is 100 <= XY >= 1000 and another variable "example" is gewerbe or privat.

richardhj commented 4 years ago

What value is inside the "conditionalFormFieldCondition" column? You can look it up with phpMyAdmin.

Cleanerrr commented 4 years ago

cond-filed-mysql cond-filed-mysql1

I don't understand why fieldset in database write PHP operator <= like &lt;=

richardhj commented 4 years ago

The field definition is already set to decodeEntities=true. I don't know why Contao is encoding the < in this case. just fix the condition via phpMyAdmin.

aschempp commented 4 years ago

I don't know why Contao is encoding the < in this case.

That to prevent HTML content if HTML is now allowed.

Cleanerrr commented 4 years ago

I don't know why Contao is encoding the < in this case.

That to prevent HTML content if HTML is now allowed.

In setting HTML is allowed. Should I make some changes in settings?