Forums

[Solve]How to display a confirmation message...

jnaylies 22 Jul, 2009
after the submit action?

In my form, on submit, I save datas into database and redirect the user to the page where he come from before the Form.

I would like to display temporary a message as: "Thank you for registration, you will receive a confirming e-mail" and then redirect (after 5 sec.) to another page.

Thanks to help me.

Jérôme
nml375 22 Jul, 2009
Hi Jerome,
This would probably be easiest achieved using a tiny javascript:

OnSubmit after email:
<?
JHTML::_('behavior.mootools');
$doc =& JFactory::getDocument();

$script = "window.addEvent('domready', function() {
  setTimeout('window.location=\'http://www.thenewurl.tld/path/to/file\'', 5000);
});";

$doc->addScriptDeclaration($script);
?>


Edit: Fixed minor typo breaking the code.
/Fredrik
jnaylies 22 Jul, 2009
Hi Fredrik

I put this code in 'Form Code'-->'onSubmit Events Code'-->'On Submit code - after sending email'
as you told me... but it's do anything!

Do I made a mistake on the place to put this code?
Or I have to active something else?

Regards
Jérôme
nml375 23 Jul, 2009
Hi Jerome,
Actually, I managed to screw up with that code. There's a single ' missing at the end of the first argument for setTimeout(), I'll update my initial post in a moment..

/Fredrik
nml375 23 Jul, 2009
G'day Jerome,
Any valid URL should do. Keep in mind that a valid URL must also contain a protocol specifier, that's why we start it with 'http://'.
I did a test-submission, and it would appear the JS-code was not included in the page at all, which I find puzzling. I did however, end up on an article-page. Could you check that the "General->Form URLs->REdirect URL" setting is empty?

/Fredrik
jnaylies 23 Jul, 2009
Hi

in the "General->Form URLs->REdirect URL", i had set the redirect url "http://www.jum31.fr/test/index.php?option=com_content&view=article&id=56&Itemid=65" because i would like to return to this page after the display of the "validation message". Maybe i misunderstood what your code make.

So I set nothing in the "General->Form URLs->REdirect URL" and then i put the "http://www.jum31.fr/test/index.php?option=com_content&view=article&id=56&Itemid=65" url in your code and now, at the submission, i have for 5 sec. the page "http://www.jum31.fr/test/index.php?option=com_chronocontact&chronoformname=Inscription_BAK" without the form (none information) and then i am redirect to the article from which i came.

this working seems fine but i would like to had a message like "thank you to register to this conf." on the 5 sec. displayed page.

i'm not sure to be clear when i read what i write above

Jérôme
nml375 23 Jul, 2009
G'day,
Moving the URL into the code is correct.

In order to add a "Thank You"-note, simply write the HTML-code (excluding <html>, <body> and such) after the ?>
Something like this:
<?
/* JS-code here... */
?>
<div class="message">Thank you for registering to this Conference. You will shortly be redirected to <a href="http://www.jum31.fr/test/index.php?option=com_content&view=article&id=56&Itemid=65" alt="Conférence de M. Fabrice BAK">Conférence de M. Fabrice BAK</a>.<br />Please use the link above if you are not automatically redirected.</div>

Of course, you don't need to use the <div> or the message CSS-class. Just a simple example on how you could style your custom thank you page.

/Fredrik
jnaylies 23 Jul, 2009
Yessssss !!!!!!!!!

Great, the message is well displayed.

thank you very much for all.

I have 1 or 2 others questions, if i would dare...

I dare :mrgreen:

In this form, there is no control on existing e-mail, so, if a person register again with the same e-mail, there is no error message. Do i have to pass by a javascript or php script?

The second problem is that i would like to have a dynamic form:
"Depart. adhésion" and "Num adhérent" fields would be displayed only when "Adhérent Jumeaux et Plus" item is selected in "Qualité" choice.


Jérôme
nml375 23 Jul, 2009
Well,
There are some ways of checking this... The first requirement however, is that you enable the DB storage, so that we have a database of email addresses to search for. If this is not already enabled, I believe you'll find some information on this spread through the forum and/or the guides. Otherwise, the process isn't that difficult using the "Create Database" wizard..

Once you've got the DB-storage set up, all we need to do is execute a simple SQL-query and test the result.
Server-side Validation:
<?
$db =& JFactory::getDBO();

$query = sprintf('SELECT COUNT(*) FROM %s WHERE %s = %s',
  $db->nameQuote('jos_myregisteredtable'),
  $db->nameQuote('email'),
  $db->Quote(JRequest::getString('email', ''))
);

$db->setQuery($query);

if ($db->loadResult() != 0 || JRequest::getString('email', '') == '') {
  return 'Sorry, but you have already registered for this Conference. You cannot register again using the same email address.';
}
?>


/Fredrik
jnaylies 23 Jul, 2009
That's work well, good.

I think it is normal that the form is cleared after the error message and all informations have to been typed again?

No idea for the dynamic form?

Promise, it's the last question 😶
GreyHead 23 Jul, 2009
Hi Jérôme,

In the Form General Tab set "Republish fields if error occured" to 'Tryto Republish'

Bob
nml375 23 Jul, 2009
There is an option to tell CF to try and republish the form data. There are, however, some cases where this does not work for some reason or other. You'll find this setting on the General tab under "Other Form Settings". Be advised that this might very well break when generating dynamic forms...

As for Dynamic Forms, I believe the simplest approach would be a tiny JScript that toggles the visibility property of a container (<div> or such) or the object itself.. You will, however, have to edit the form by hand rather than using the wizard.

The following should do the trick, and should be added in the Form JavaScript box:
window.addEvent('domready', function() {
  var quality = $('select_5');
  quality.addEvent('change', function(event) {
    var selected = quality.getValue();
    switch (selected) {
     case 'Adhérent Jumeaux et Plus':
      $('text_6').style.visibility = 'visible';
      $('text_7').style.visibility = 'visible';
      break;
     default:
      $('text_6').style.visibility = 'hidden';
      $('text_7').style.visibility = 'hidden';
    }
  });
});


Edit: Fixed bug; visibility property should be 'hidden', not 'hide'...
/Fredrik
jnaylies 23 Jul, 2009
Thanks GreyHead and Fredrik

I'll test that toonight and then publish my site.

Your help was greatfull

Hope to discuss with you for another think than problem...

Jerome
jnaylies 23 Jul, 2009
bad news😢

The javascript code don't work. I put it in the 'Form Code'-->'Main OnLoad/View Code'-->'Form Javascript' box as you said!

the link is the same if you want to play with the form

Jérôme
nml375 23 Jul, 2009
Sorry, my bad.

'hide' should really be 'hidden' in that script.

/Fredrik
nml375 23 Jul, 2009
Updated version, proper style properties, and applies the property to the parent div, rather than the input box - thus also hiding the label..

window.addEvent('domready', function() {
  var quality = $('select_5');
  quality.addEvent('change', function(event) {
    var selected = quality.getValue();
    switch (selected) {
     case 'Adhérent Jumeaux et Plus':
      $('text_6').getParent().style.visibility = 'visible';
      $('text_7').getParent().style.visibility = 'visible';
      break;
     default:
      $('text_6').getParent().style.visibility = 'hidden';
      $('text_7').getParent().style.visibility = 'hidden';
    }
  });
});


/Fredrik
jnaylies 23 Jul, 2009
That's better🙂

is-it possible to make textbox hidden at the start of the form?

The default choice is 'Selectionner' and not 'Adhérent Jumeaux et Plus' so, the textbox are visible until i select a quality
nml375 23 Jul, 2009
Sure,
You could try and add the visibility property directly into the form, but on the other hand, this code should work better with the wizard editor..
window.addEvent('domready', function() {
  var quality = $('select_5');
  quality.addEvent('change', function(event) {
    var selected = quality.getValue();
    switch (selected) {
     case 'Adhérent Jumeaux et Plus':
      $('text_6').getParent().style.visibility = 'visible';
      $('text_7').getParent().style.visibility = 'visible';
      break;
     default:
      $('text_6').getParent().style.visibility = 'hidden';
      $('text_7').getParent().style.visibility = 'hidden';
    }
  });
  $('text_6').getParent().style.visibility = 'hidden';
  $('text_7').getParent().style.visibility = 'hidden';
});


/Fredrik
jnaylies 23 Jul, 2009
I'm installing the final site so i'll test this last code after.

Again, thanks a lot for your help

Jérôme
jnaylies 23 Jul, 2009
After some instal and some test, all is OK.

Again thanks to you

Jérôme
This topic is locked and no more replies can be posted.