Formbuilder syntax problem

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Formbuilder syntax problem

Post by pierrepercee »

Hello,

In formbuilder I created a bootstrap template based on the fields name. I only left the validation logic at the start of the template.
Stupid question: in my original template inside the

Code: Select all

 {foreach from=$fields item=entry}
loop I have the following syntax

Code: Select all

</label>{if $entry->valid == 0}<span class="error"> {$entry->error}<i class="icon-right-dir"></i></span> {/if}
.
Is there a way to catch this error for each field individually? Sure, and the syntax should be simple, but... ::)
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Formbuilder syntax problem

Post by DIGI3 »

I haven't tested, but I would think {if $myfield-->valid == 0}{$myfield->error}{/if} would do it, where $myfield is your field name.
Not getting the answer you need? CMSMS support options
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Hello Digi3,

Thanks but it's not working at all (->valid not -->valid). I try this first... :) Same idea, unfortunately... :)
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Formbuilder syntax problem

Post by DIGI3 »

I think you can also get fields with $fields->myfield, but you can always try <pre>{$fields|print_r}</pre> and <pre>{$myfield|print_r}</pre> to see what's there.
Not getting the answer you need? CMSMS support options
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

It returns this for one field. I'm sorry but it doesn't tell me how i can call the "require" value. I clearly see the array but...

Code: Select all

[fbrp__28] => stdClass Object ( [id] => 28 [display] => 1 [required] => 1 [required_symbol] => * [css_class] => [helptext] => [field_helptext_id] => fbrp_ht_28 [valid] => 1 [error] => [hide_name] => 0 [has_label] => 1 [needs_div] => 1 [name] => Nom [input] => [logic] => [values] => [value] => [smarty_eval] => 0 [multiple_parts] => 0 [label_parts] => 1 [type] => Ligne de texte simple [input_css_id] => fbrp__28 [input_id] => fbrp__28 [alias] => nom )
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Formbuilder syntax problem

Post by Jo Morg »

DIGI3 got it right although with a typo on one of the examples that might have mislead you... So objects have a syntax like $myfieldname->property_i_want_to_use. So $fbrp__28->required should work.

Code: Select all

{if $fbrp__28->valid === 0}{$fbrp__28->error}{/if}
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Hello,

Thanks ! I think I need a vitamin cure. Nothing works as expected...

Code: Select all

<h1>Start test</h1>
{if $fbrp_22->required == 0}
Yes it works
{/if}
<h1> End test </h1>
$fbrp_22 is "required", I checked well. And.... I won a superb "Yes it works". Probably aspirin!

My second problem: when I submit a form with an error, it does not keep the data previously entered. The default contact form retains them well. I am unable to see what is happening exactly.
Below the shipwreck, what is it called? Sorry for my newbie questions. :-\

Voilà mon formulaire complet :

Code: Select all

{* DEFAULT FORM LAYOUT / pure CSS *}
{literal}
<__script__ type="text/javascript">
function fbht(htid)
	{
		var fbhtc=document.getElementById(htid);
		if (fbhtc)
			{
			if (fbhtc.style.display == 'none')
				{
				fbhtc.style.display = 'inline';
				}
			else
				{
				fbhtc.style.display = 'none';
				}
			}
}
</__script>
{/literal}
<div class="formgen">
<h2 class="ala2">Formulaire de contact</h2>
<p class="obligatoire">Les champs dont l'intitulé est suivi d'un astérisque doivent impérativement être renseignés</p>
{$fb_form_header}
{if $fb_form_done == 1}
	{* This first section is for displaying submission errors *}
	{if isset($fb_submission_error) && $fb_submission_error}
		<div class="error_message">{$fb_submission_error}</div>
		{if isset($fb_show_submission_errors) && $fb_show_submission_errors}
			<div class="error">
			<ul>
			{foreach from=$fb_submission_error_list item=thisErr}
				<li>{$thisErr}</li>
			{/foreach}
			</ul>
		</div>
		{/if}
	{/if}
{else}
	{* this section is for displaying the form *}
	{* we start with validation errors *}
	{if isset($fb_form_has_validation_errors) && $fb_form_has_validation_errors}
		<div class="error_message"><h3>Liste des champs obligatoires non renseignés</h3>
		<ul role="alert">
		{foreach from=$fb_form_validation_errors item=thisErr}
			<li>{$thisErr}</li>
		{/foreach}
		</ul>
		</div>
	{/if}
	{if isset($captcha_error) && $captcha_error}
		<div class="error_message">{$captcha_error}</div>
	{/if}

	{* and now the form itself *}

	{$fb_form_start}
	<div>{$fb_hidden}</div>
<h1>mon test</h1>
{if $fbrp_22->required == 0}Yes it works{/if}
<h1> fin test </h1>
	<div class="row parki">

<div class="col-sm-12 col-md-3">
<label for="fbrp__30" class="labsur">Civilités*</label> 
</div>
<div class="col-sm-12 col-md-9">
<select class="cms_dropdown" name="cntnt01fbrp__30" id="fbrp__30"><option class="form-control form-control-lg" value="" selected="selected"> Choisir civilités</option><option class="form-control form-control-lg" value="1">Madame</option><option class="form-control form-control-lg" value="2">Monsieur</option></select>
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<div class="required"><label for="fbrp__22" class="labsur">Nom*</label></div>
</div>
<div class="col-sm-12 col-md-9">
<input type="text" name="cntnt01fbrp__22" class="form-control form-control-lg" value="" size="25" maxlength="65" id="fbrp__22">
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__23" class="labsur">Prénom*</label> 
</div>
<div class="col-sm-12 col-md-9">
<input type="text" name="cntnt01fbrp__23" class="form-control form-control-lg" value="" size="25" maxlength="64" id="fbrp__23">
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__25" class="labsur">Email*</label>
</div>
<div class="col-sm-12 col-md-9">
<input type="email" name="cntnt01fbrp__25[]" class="form-control form-control-lg" value="" size="25" maxlength="128" id="fbrp__25">
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__26" class="labsur">Vérification Email*</label> 
</div>
<div class="col-sm-12 col-md-9">
<input type="email" name="cntnt01fbrp__26" class="form-control form-control-lg" value="" size="25" maxlength="128" id="fbrp__26">
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__29" class="labsur">Objet*</label> 
</div>
<div class="col-sm-12 col-md-9">
<input type="text" name="cntnt01fbrp__29" class="form-control form-control-lg" value="" size="25" maxlength="140" id="fbrp__29">
</div>
</div>

<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__32" class="labsur">Votre message*</label> 
</div>
<div class="col-sm-12 col-md-9">
<textarea name="cntnt01fbrp__32" id="fbrp__32" class="form-control form-control-lg" cols="80" rows="8"></textarea>
</div>
</div>
<div class="col-sm-12 bigtak"><h3 class="cfacu">Champs facultatifs</h3>
<div class="row parki">

<div class="col-sm-12 col-md-3">
<label for="fbrp__36" class="labsur">Code postal</label>
</div>
<div class="col-sm-12 col-md-9">
<input type="text" name="cntnt01fbrp__36" class="form-control form-control-lg" value="" size="12" maxlength="12" id="fbrp__36">
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__37" class="labsur">Ville</label>
</div>
<div class="col-sm-12 col-md-9">
<input type="text" name="cntnt01fbrp__37" class="form-control form-control-lg" value="" size="25" maxlength="80" id="fbrp__37">
</div>
</div>
</div>
<div class="col-sm-12 bigtak"><h3 class="cfacu">Accord RGPD</h3>
<div class="row parki">
<div class="col-sm-12">
<p>RGPD - J'autorise ce site à enregistrer les informations fournies. J'ai lu et j'accepte sans réserve <a href="politique-de-confidentialite.html">la politique de confidentialité</a> du site.</p>
</div>
</div>
<div class="row parki">
<div class="col-sm-12 col-md-3">
<label for="fbrp__28" class="labsur">Accord RGPD*</label> 
</div>
<div class="col-sm-12 col-md-9">
<input type="checkbox" class="form-control form-control-lg" name="cntnt01fbrp__28" value="t" id="fbrp__28">
</div>
</div>
</div>
<div class="col-sm-12 bigtak"><h3 class="cfacu">Antispam</h3>

<div class="row parki">
<div class="col-sm-12 col-md-4">
{$graphic_captcha}
</div>
<div class="col-sm-12 col-md-4">
{$title_captcha}
</div>
<div class="col-sm-12 col-md-4">
{$input_captcha|replace:'cms_textfield':'form-control'}
</div>
</div>
<div class="row parki"><input class="formpsubmit" name="cntnt01fbrp_submit" id="cntnt01fbrp_submit" value="Envoyer" type="submit"></div>
</div>
	</div>
{/if}
	{$fb_form_end}
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Formbuilder syntax problem

Post by Jo Morg »

A snippet from an old form I have, just changed the field variable to match yours:

Code: Select all

<div class="form-group {if $fb_form_has_validation_errors|default:false}
  {if $fbrp__37->valid}has-success{else}has-error{/if}{/if}">
  <label for="{$fbrp__37->alias}">label here {if $fbrp__37->required}*{/if}</label>
  <input name="{$actionid}{$fbrp__37->input_id}"
         value="{$fbrp__37->value}"
         id="{$fbrp__37->alias}"
         class="form-control"
         type="text" {if $fbrp__37->required}required{/if} >
    {if $fb_form_has_validation_errors|default:false}
        {if !$fbrp__37->valid}
          <span id="helpBlock_{$fbrp__37->alias}" class="help-block">
        {$fbrp__37->error}
      </span>
        {/if}
    {/if}
</div>
It's old bootstrap markup so it may need some tweaking. This should work fine, if not you have more stuff to debug other than just the form template.
HTN
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Thanks,

I try the snippet but nothing work at all. I created a new form very simple with 4 fields type:

Ordinary : not requested , no validation
Nom : requested , no validation
Code postal: requested , validation (numeric)
Numero dans la rue : not requested, validation (integer)

Form template is :

Code: Select all

{* DEFAULT FORM LAYOUT / pure CSS *}
{literal}
<__script__ type="text/javascript">
function fbht(htid)
	{
		var fbhtc=document.getElementById(htid);
		if (fbhtc)
			{
			if (fbhtc.style.display == 'none')
				{
				fbhtc.style.display = 'inline';
				}
			else
				{
				fbhtc.style.display = 'none';
				}
			}
}
</__script>
{/literal}
{$fb_form_header}
{if $fb_form_done == 1}
	{* This first section is for displaying submission errors *}
	{if isset($fb_submission_error) && $fb_submission_error}
		<div class="error_message">{$fb_submission_error}</div>
		{if isset($fb_show_submission_errors) && $fb_show_submission_errors}
			<div class="error">
			<ul>
			{foreach from=$fb_submission_error_list item=thisErr}
				<li>{$thisErr}</li>
			{/foreach}
			</ul>
		</div>
		{/if}
	{/if}
{else}
	{* this section is for displaying the form *}
	{* we start with validation errors *}
	{if isset($fb_form_has_validation_errors) && $fb_form_has_validation_errors}
		<div class="error_message">
		<ul>
		{foreach from=$fb_form_validation_errors item=thisErr}
			<li>{$thisErr}</li>
		{/foreach}
		</ul>
		</div>
	{/if}
	{if isset($captcha_error) && $captcha_error}
		<div class="error_message">{$captcha_error}</div>
	{/if}

	{* and now the form itself *}
	{$fb_form_start}
	<div>{$fb_hidden}</div>
	
	
<div class="form-group {if $fb_form_has_validation_errors|default:false}
<h3> no validation not required</h3>
  {if $fbrp__45->valid}has-success{else}has-error{/if}{/if}">
<label for="{$fbrp__45->alias}">ordinary (nr nv) {if $fbrp__45->required}*{/if}</label>
<input name="{$actionid}{$fbrp__45->input_id}"
         value="{$fbrp__45->value}"
         id="{$fbrp__45->alias}"
         class="form-control"
         type="text" {if $fbrp__45->required}required{/if} >
    {if $fb_form_has_validation_errors|default:false}
        {if !$fbrp__45->valid}
          <span id="helpBlock_{$fbrp__45->alias}" class="help-block">
        {$fbrp__45->error}
      </span>
        {/if}
    {/if}
	</div>
	
	<div class="form-group {if $fb_form_has_validation_errors|default:false}
	<h3> Required no validation</h3>
  {if $fbrp__42->valid}has-success{else}has-error{/if}{/if}">
<label for="{$fbrp__42->alias}">nom (r) {if $fbrp__42->required}*{/if}</label>
<input name="{$actionid}{$fbrp__42->input_id}"
         value="{$fbrp__42->value}"
         id="{$fbrp__42->alias}"
         class="form-control"
         type="text" {if $fbrp__42->required}required{/if} >
    {if $fb_form_has_validation_errors|default:false}
        {if !$fbrp__42->valid}
          <span id="helpBlock_{$fbrp__42->alias}" class="help-block">
        {$fbrp__42->error}
      </span>
        {/if}
    {/if}
	</div>
	
	<div class="form-group {if $fb_form_has_validation_errors|default:false}
	<h3> Required and validation</h3>
  {if $fbrp__43->valid}has-success{else}has-error{/if}{/if}">
<label for="{$fbrp__43->alias}">code postal (r v) {if $fbrp__43->required}*{/if}</label>
<input name="{$actionid}{$fbrp__43->input_id}"
         value="{$fbrp__43->value}"
         id="{$fbrp__43->alias}"
         class="form-control"
         type="text" {if $fbrp__43->required}required{/if} >
    {if $fb_form_has_validation_errors|default:false}
        {if !$fbrp__43->valid}
          <span id="helpBlock_{$fbrp__43->alias}" class="help-block">
        {$fbrp__43->error}
      </span>
        {/if}
    {/if}
	</div>
	
		<div class="form-group {if $fb_form_has_validation_errors|default:false}
		<h3> just validation</h3>
  {if $fbrp__44->valid}has-success{else}has-error{/if}{/if}">
<label for="{$fbrp__44->alias}">numero dans la rue (v) {if $fbrp__44->required}*{/if}</label>
<input name="{$actionid}{$fbrp__44->input_id}"
         value="{$fbrp__44->value}"
         id="{$fbrp__44->alias}"
         class="form-control"
         type="text" {if $fbrp__44->required}required{/if} >
    {if $fb_form_has_validation_errors|default:false}
        {if !$fbrp__44->valid}
          <span id="helpBlock_{$fbrp__44->alias}" class="help-block">
        {$fbrp__44->error}
      </span>
        {/if}
    {/if}
	</div>



	
	{if isset($has_captcha) && $has_captcha == 1}
		<div class="captcha">{$graphic_captcha}{$title_captcha}<br />{$input_captcha}</div>
	{/if}
	<div class="submit">{$prev}{$submit}</div>
	</div>
	{$fb_form_end}
{/if}
The standard form "Contact Form" seem's to perfectly works. It keeps data when submited with an error (requested or validation) and back to the form. I'm probably making a huge mistake in my template. I do not see...

Anyway, thanks for the help
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Formbuilder syntax problem

Post by Jo Morg »

pierrepercee wrote: Sat Jul 16, 2022 10:55 am The standard form "Contact Form" seem's to perfectly works. It keeps data when submited with an error (requested or validation) and back to the form. I'm probably making a huge mistake in my template. I do not see...
Or in the form settings?
So, back to the basics:
  • validate the rendered form HTML to look for errors -- simple HTML errors may prevent the form submission;
  • with a copy of the contacts form that works try to add custom code for one field at the time (you can exclude each field from the loop with a simple {if...}...{/if} clause that tests for its name or alias) -- test one at the time;
  • look for PHP errors on the server PHP errors log, there may be clues there;
  • make sure you are running PHP 7.4 at the most with FormBuilder; it's not yet ready for latest PHP versions;
HTH
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Hello,

I did a CMSMS fresh install, with php 7.4.
No new form , no parameter specified just "ContactForm". I added a simple field "testform" line input, required, and then I edited the default ContactForm template.
I just added

Code: Select all

<h4>syntaxe 1</h4>
{if $fbrp__29->required ==1} requis {else}non requis{/if}
<h4>syntaxe 2</h4>
{if $fbrp__29->required} requis {else}non requis{/if}
<h4>syntaxe 3</h4>
{if $fbrp__29-->required==1} requis {else}non requis{/if}
<h4>syntaxe 4</h4>
{if $fbrp__29-->required} requis {else}non requis{/if}
just after {/foreach}.
And "testform" is "fbrp__29"...
And "voilà le résultat"
[img]https://imgur.com/FZ8Kc6S[img]

none of these syntaxes works.... :)
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Hello,

I try with Formbuilder 1.1.1 and Formbuilder 0.8.1.6. Same thing.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Formbuilder syntax problem

Post by Jo Morg »

try {$testform->required} or {$fld_29->required}... {$fbrp__....} was a typo from copy and pasting... my bad.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
pierrepercee
Forum Members
Forum Members
Posts: 152
Joined: Thu Jan 10, 2013 8:02 am

Re: Formbuilder syntax problem

Post by pierrepercee »

Yes,
got it. It works only with

Code: Select all

{$testform->required}
, not working with

Code: Select all

{if $fld_29...
Will try with "validated" now...
This mode of operation is not great. For languages ​​with accents, if there is a special character in the field name...
I don't know what this implies in terms of development, but being able to access the field via $fld_x ​​would be much less tricky.

Many thanks !
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1922
Joined: Mon Jan 29, 2007 4:47 pm

Re: Formbuilder syntax problem

Post by Jo Morg »

Actually {$fbrp__....} should work too, I just double checked...
pierrepercee wrote: Mon Jul 18, 2022 10:08 am This mode of operation is not great. For languages ​​with accents, if there is a special character in the field name...
I don't know what this implies in terms of development, but being able to access the field via $fld_x ​​would be much less tricky.
It's not tricky as you might think: FormBuilder removes any diacritics and invalid characters from the name, replacing spaces with underscores. Since version 8.x IIRC if you set an alias for a field it can also be used, so in practical terms the module creates an alias from the name and you can use your own alias (which is also used in the field HTML class when using the {$myfield->field} auto rendering). TBH I find the use of aliases and field names much more intuitive than just field numbers... I always know the field names or aliases and I can reuse them per form, so they are only unique on each form but not on the whole FB system. I can even reuse templates from other forms this way and just tweak a thing or too as needed.
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).
Code of Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
Post Reply

Return to “Modules/Add-Ons”