This one works a treat, seperated error messages. If you absolutely MUST have the same fields...
2 Forms, 1 Field
We have to do some foolery here, please stand byfirst things first, we need to create a field in freeform, lets call it fid
. This field is required so we can pass the forms ID through Freeform (spinning anit cleans fields that arn't part of the form collection).
So as per the example up for you nowabove each form collection has a fid
field and a test_text_1
field. Dont worry, we're never going to display or use this field, its just so we can track through...
Then edit your template to be this (PHP on Input) :
<?php
//this variable holds the passed form ID, if submitted
$submittedFid = NULL;
//get the freeform params ID (needed for later)
$paramsId = ee()->session->flashdata('freeform_errors');
//was there a params ID set (if not there's no submission, continue)
if ( !empty( $paramsId ) ) {
//get the freeform params info from the db
$res = ee()->db->where('params_id', $paramsId)->get('freeform_params');
//if we have a result, gravy! lets sniff for the submitted form ID
if ( $res !== FALSE ) {
//extract the data/info
$res = array_shift($res->result_array());
$paramInfo = json_decode($res['data'], TRUE);
//did we have a form ID passed through??
if ( !empty( $paramInfo['inputs']['fid'] ) ) {
//set the form ID that was submitted
$submittedFid = $paramInfo['inputs']['fid'];
}
}
}
?>
{!-- Here we display form 1 --}
<h3>Form 1</h3>
{exp:freeform:form
form_name="form1"
required="test_text_1"
inline_errors="yes"
}
{!-- here we pass our super secret FID! for this one its '1st_form' --}
<input type="hidden" name="fid" value="1st_form" />
{!-- Display the field --}
<p><label>{freeform:label:test_text_1}</label> {freeform:field:test_text_1}</p>
{!-- Display Error messages if any. First use PHP to see if this is the right form --}
<?php if( !empty($submittedFid) && $submittedFid == "1st_form" ) { ?>
{!-- Standard Fredform error syntax --}
{if freeform:error:test_text_1}
<span class="error">{freeform:error:test_text_1}</span>
{/if}
<?php } ?>
{!-- submit button --}
<p>{freeform:submit}</p>
{/exp:freeform:form}
<hr />
{!-- Here we display form 2 --}
<h3>Form 2</h3>
{exp:freeform:form
form_name="form2"
required="test_text_1"
inline_errors="yes"
}
{!-- here we pass our super secret FID! for this one its '2nd_form' --}
<input type="hidden" name="fid" value="2nd_form" />
{!-- Display the field --}
<p><label>{freeform:label:test_text_1}</label> {freeform:field:test_text_1}</p>
{!-- Display Error messages if any. First use PHP to see if this is the right form --}
<?php if( !empty($submittedFid) && $submittedFid == "2nd_form" ) { ?>
{!-- Standard Fredform error syntax --}
{if freeform:error:test_text_1}
<span class="error">{freeform:error:test_text_1}</span>
{/if}
<?php } ?>
{!-- submit button --}
<p>{freeform:submit}</p>
{/exp:freeform:form}
There you have it! tested and works a treat (EE 2.9.2 + Freeform 4.2.2).
As always if this gets you there, help the site and please mark as the answer.