Forums

Hide form module on all pages after submit

megana 14 Oct, 2014
Hello, I have a site where the client wants to have a form in the sidebar on every single page. After a user submits the form, they want the form to NOT display in the sidebar while the user continues to browse the site. Any tips on how to do that? Much thanks!
GreyHead 14 Oct, 2014
Answer
Hi megana,

Basically what you need to do is two things. A.keep a record that they have completed the form and B.to hide the form if they have.

A. I'd add a Custom Code action to form On Submit event after any validation or security checks with code like this in it to set a variable in the User Session to a value of true
<?php
$session = JFactory::getSession();
$session->set('form_complete', true);
?>


B. I'd add an Event Switcher in the Form On Load event to check the session (this sets the default value to false)
<?php
$session = JFactory::getSession();
$form_complete = $session->get('form_complete', false);
if ( $form_complete ) {
  return 'success';
}
?>

Then in the On Success event of the Event Switcher you need to add something to hide the form. The simplest is probably just a line of CSS
<?php
$doc = JFactory::getDocument();
$style = "
#chronoform_form_name {
  display: none;
}
";
$doc->addStyleDeclaration($style);
?>

There are other ways you could use the Event Switcher,for example you could put the HTML (Show Form) action in one event and an HTML div with a message in the other.

Bob

Note the code is not tested and may need debugging!!
megana 14 Oct, 2014
Thanks for the superfast reply! I'll see if I can get that working. 🙂
megana 14 Oct, 2014
Works like a charm, even displays my thank you message before it starts hiding the form. Thanks so much!
This topic is locked and no more replies can be posted.