Forums

Server side validation error messages are not displayed

enounce 28 Sep, 2010
I'm trying to use the server side validation. The PHP block returns a string with the error message.

if ($result) {
....
} else {
return 'Sorry, but your email address was not found, please try again.';
}

When there is no error the form works fine and data is saved and emails sent. When there is an error, the page with the form just reloads with a blank form and no error is indicated and the user just has to guess an renter. Could there be a conflict between JoomSEF and Chrono that causes this?
GreyHead 28 Sep, 2010
Hi enounce,

Please post a link to the form so we can take a quick look.

Can you also post the rest of the server-side validation code?

The error messages should display, so I suspect that something else may be going on. There might be an SEF problem but usually the Server-side validation works OK with SEF.

Bob
enounce 28 Sep, 2010
Here is the latest form I'm working on:
SEF Link:
http://www.enounce.com/refer-friend

I hadn't tried this before but here is the link from the ChronoForms panel with an Itemid added to the end.
http://www.enounce.com/index.php?option=com_chronocontact&chronoformname=ReferAFriend&Itemid=161

I hadn't tried the direct link before (non sef) but it appears to work there.

I've changed the validation code to force it to error so there is no question about an error in the PHP code. The only code in the Service Side Validation PHP block is:
<?php
return 'Sorry, but your email address was not found, please try again.';
?>

It doesn't work with the SEF URL but does for the non-sef url.

Also, I've tried leaving the Submit URL blank and and manually setting it. Currently it is set to:
/index.php?option=com_chronocontact&task=send&chronoformname=ReferAFriend&Itemid=161
GreyHead 28 Sep, 2010
Hi enounce,

There's something odd with the form. I couldn't get it to submit at all from the bare form. Seems to be OK from the page but . . .

Please try removing the OnSubmit URL and see if that helps - ChronoForms should add the ITemID itself.

Bob
enounce 28 Sep, 2010
Submit url is gone.

It seems that the plug-in to embed the form on a page may have something to do with the issue.
This URL is embedded in the content of an article:
http://www.enounce.com/refer-friend
This URL just shows the form again after submitting.

This URL is the bare form:
http://www.enounce.com/index.php?option=com_chronocontact&chronoformname=ReferAFriend&Itemid=161
This url displays the correct error for me when I submit.

I also noticed that in the bare form, the styles are different on the form input elements. I don't know if that's a clue as to something missing or being added when the page
enounce 29 Sep, 2010
Ok, that is strange because both have the exact same action.

In page:

<form name="ChronoContact_ReferAFriend" id="ChronoContact_ReferAFriend" method="post" action="http://www.enounce.com/index.php?option=com_chronocontact&task=send&chronoformname=ReferAFriend&Itemid=161" > 

Bare From:

<form name="ChronoContact_ReferAFriend" id="ChronoContact_ReferAFriend" method="post" action="http://www.enounce.com/index.php?option=com_chronocontact&task=send&chronoformname=ReferAFriend&Itemid=161" > 

In "Tamper Data" (like Firebug), submitting the SEF URL, I see that the response is 301 redirect back to the /refer-friend url. I don't see the failed to load source.

Submitting the bare form just loads the bare form again with no redirect and the correct form displayed error message at the top.

I've looked at the code and think the difference is here in "showFormErrors" (line 265 of chronoform.php):
		if($MyForm->formerrors){
			if($session->get('cfreturnurl_'.$formname, '', md5('chrono'))){				
				$session->set("chrono_form_errors_".$formname, $MyForm->formerrors, md5('chrono'));
				$session->set("chrono_form_data_".$formname, $MyForm->posted, md5('chrono'));				
				//$mainframe->redirect(str_replace('&cfshowerrors=1', '', JRequest::getVar('cfreturnurl')).'&cfshowerrors=1');
				
				$mainframe->redirect($session->get('cfreturnurl_'.$formname, '', md5('chrono')));
			}
			//$MyForm->showForm($MyForm->formrow->name, $posted);
			return true;
		}else{


If cfreturnurl is set, it does the redirect. If it's not than it just returns and the next line after returning from "showFormErrors" is to show the form. Looking for "cfreturnurl_" I found it set in only one location here in chronocontact.html.php (line 187 of my version):

        <?php if($MyForm->pagetype != 'chronocontact'){ ?>
        	<?php $session->set("cfreturnurl_".$MyForm->formrow->name, $MyForm->selfURL(), md5('chrono')); ?>
        <?php }	?>

where the cfreturnurl_ is set to the self url, in this case /refer-friend.

I think that's all working as it should but why isn't the session being preserved. The form is not repopulated and the error isn't displayed. It's a new form. That might be where we need to look.
enounce 29 Sep, 2010
Looking at more code, I may have discovered the problem. When chronocontact.php is loaded the default action is to call the function "showform" which calls the CFChronoForm->showForm().

In CFChronoForm->showForm() at the top is this code:


		//if(!trim($session->get('cfreturnurl_'.$formname, '', md5('chrono')))){
			$session->clear('chrono_form_errors_'.$formname, md5('chrono'));
			$session->clear('chrono_form_data_'.$formname, md5('chrono'));
			$session->clear('cfreturnurl_'.$formname, md5('chrono'));
		//}


and the if statement to check if the page was arrived at through a redirect are commented out and the errors and data are cleared every time a form is displayed. Since the errors are set in the session to carry over to the form this way, the errors are lost. Looking at chronocontact.html.php, showForm() function around line 160,

		<?php
			$session =& JFactory::getSession();
		?>
		<?php if($MyForm->formerrors){ ?>
            <span class="cf_alert"><?php echo '<ol>'.$MyForm->formerrors.'</ol>'; ?></span>
		<?php } ?>

I see that the form errors are only received from the Form and I couldn't find any place where the form data and errors are loaded back into the MyForm object from the session. I guess that should be in getForm called from the constructor of CFChronoForm. Maybe this is fixed in a later version and I need to update.
This topic is locked and no more replies can be posted.