Redirect URL and Thank You Message

zendiko 03 Dec, 2008
Hey guys...

So I have a contact form and after a successful submission I want the form to go back to the page that the form is on (basically php_self) so I put the same url in the form redirect field... but in my "onSubmit after Email" field I had:
<span class="cf_msg">Thanks <? echo $_POST['name'] ?>! Your email has been submitted to TOSS.</span>


which is basically supposed to create a green message just like the error message above the contact form so they know that it has been successfully submitted...

however... because i put the redirect, that php is not being sent to that page. Is there a way to get it to the other page? or hijack Joomla's "message" module and send it through that?

Thanks!

Aaron
GreyHead 03 Dec, 2008
Hi Aaaron,

You could put a delay in the ReDirect - I remember someone posting about that here but better to hijack the message system.
<?php
global $mainframe;
$mainframe->enqueuemessage("Thanks ".$_POST['name']."! Your email has been submitted to TOSS.");
?>

Bob
zendiko 03 Dec, 2008
Sweet! That worked... is there a way to tell joomla what type of message it is? I have different styles for error, message or notice... this one came in as a message. I would love if i can get it as a notice.

Thanks!
GreyHead 03 Dec, 2008
Hi Aaron,

There are a few options - from memory
$mainframe->enqueuemessage($msg, 'error');
$mainframe->enqueuemessage($msg, 'info');
$mainframe->enqueuemessage($msg, 'alert');
These may not be correct! Possibly also 'notice' & 'message' . . .

Bob
zendiko 07 Dec, 2008
Hey,

This solution worked for my forms once they were submitted... but now it seems I am having the same problem when my error trap goes off.

Here is my error trap code:
<?php 

function is_valid_email($sender_mail) { 
    if(ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $sender_mail)) {
		return 0;
    }
	else{
        return 1;
    } 
}

$emailvalid = is_valid_email($_POST['email']);
$msg = "";
if($_POST['name'] == '')
$msg .= "<li>Please enter your name</li>";


if($_POST['email'] == '' || $emailvalid == 1)
$msg .= "<li>Please enter a valid email address</li>";

if($_POST['message'] == '')
$msg .= "<li>Please enter a message</li>";

if($msg != ''){
return $msg;
 }

?>


Once the user submits, if they are missing their name or one of those fields, they are taken to a new page with just the form and error displayed. I want them to stay on the same form and display the error on the top.

So I tried to take out
return $msg;


and I put in this instead:

global $mainframe;
$mainframe->enqueuemessage($msg,'error');



This worked and kept the original page upon submission and showed the error above... but it also submitted the form and had a thank you message... so it didnt execute the error traps... So how do I still execute the error traps while keeping the redirect on the same page?

Thanks!
GreyHead 07 Dec, 2008
Hi zendiko,

Where have you got the error trap code? I think it probably needs to go in the server side validation box and needs to return the error message.

Bob
zendiko 07 Dec, 2008
Yeah I had it in the server side validation box.
Max_admin 08 Dec, 2008
Hi zendiko,

sorry but I couldn't understand all the problem here but the server side validation will detect any thing returned, and if there is any then the form submission will be halted just as if a wrong verification code is entered, whats the problem you have ?

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 08 Dec, 2008
Hi zendiko,

I think that the code you have here no longer returns anything so doesn't trip the error message. Try this version in the Server Side Validation box. I've simplified it a bit:
<?php
$msg = array();
$is_valid_email = ereg("([[:alnum:]\.\-]+)(\@[[:alnum:]\.\-]+\.+)", $_POST['email']);
if ( $_POST['name'] == '' ) {
    $msg[] = "Please enter your name";
}
if ( !$_POST['email'] || !$is_valid_email ) {
    $msg[] = "Please enter a valid email address";
}
if ( !$_POST['message'] ) {
    $msg[] = "Please enter a message";
}
if ( !empty($msg) ) {
    global $mainframe:
    for each ($msg as $message) {
       // or you could use explode to build a <ul> here
       $mainframe->enqueuemessage($msg, 'error');
    }
    return true; // to trigger the validatiion error 
}
?>

Bob
zendiko 10 Dec, 2008
Bob,

I tried that code and the error traps didnt work and it just said "Thanks for submitting"...

So I took this code out to see what would happen to diagnose the issue:
global $mainframe:
    for each ($msg as $message) {
       // or you could use explode to build a <ul> here
       $mainframe->enqueuemessage($msg, 'error');
    }


And the error traps worked except it opened a new page with just the form and the error said "1"
Max_admin 10 Dec, 2008
try to replace:
if ( !empty($msg) ) {
    global $mainframe:
    for each ($msg as $message) {
       // or you could use explode to build a <ul> here
       $mainframe->enqueuemessage($msg, 'error');
    }
    return true; // to trigger the validatiion error
}


with:


if(count($msg)){
return implode('\n', $msg);

}


Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
zendiko 10 Dec, 2008
That got the error traps back but it didnt keep it on the same page...
it went to: index.php?option=com_chronocontact&task=send&chronoformname=ContactUs
Max_admin 10 Dec, 2008
Hi zendiko, whats the "same page" you are expecting the form to go to ?

Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
zendiko 10 Dec, 2008
That form is on the page index.php/contact-us. If there were errors I wanted them to show up on that page and not pull the form out of the page... I have the form in a module underneath the content... so when it pulls it out I lose all of the modules and content.
zendiko 11 Dec, 2008
When it submits correctly... the thank you success message pops up and it stays on the same page.... so... hmmm... not sure why the errors are making it jump to the actual "form" page.
Max_admin 12 Dec, 2008
that's normal, I'm looking for a fix for this issue before the next release!

regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
zendiko 31 Dec, 2008
Alright... can you let me know when this fix will be available? or what the time frame is?

Thanks!

Aaron
Max_admin 31 Dec, 2008
Hi Aaron,

time frame is something hard to tell, making this fix is not easy because it has some implications over other issues, I will try to have this ready ASAP, hopefully by the 1st week in the new year!

Happy new year!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
zendiko 31 Dec, 2008
awesome... I was testing out the mootools validation but it wasnt working at all for me... I was putting the names of the required fields... for example... name, message for the required... am i doing this wrong?
GreyHead 01 Jan, 2009
Hi zendiko,

Make sure that there are no spaces between the field-names e.g. name,message

Bob
zendiko 01 Jan, 2009
Still not working... here's what my validation looks like:

[attachment=0]Picture 7.jpg[/attachment]
GreyHead 01 Jan, 2009
Hi zendiko,

Hmmm . . . In that case there's probably somethign else wrong with the form page. Have you checked for JavaScript errrors?

Bob
zendiko 01 Jan, 2009
I think it's not working because I use JQuery on my pages. hmm... is there an easy way to do a regular javascript check?
GreyHead 01 Jan, 2009
Hi zendiko,

Yes, use the FireBug extension with FireFox - absolutely indispensible for any kind of development like this. There's also a good JavaScript checker in Chrome and I hear that there's some kind of PlugIn for IE but I don't know what it is.

Bob
zendiko 02 Jan, 2009
Thanks bob.. I shouldve been more clear. Is there a quick regular javascript validation script that you have seen anyone use instead of PHP or mootools?

Thanks!
zendiko 02 Jan, 2009
nevermind. i found a script and got it working!
GreyHead 02 Jan, 2009
Hi zendiko,

Glad you found a script.

To answer the earlier question . . . PHP is the language for server side validation which is more secure and reliable than client side. JavaScript is the client side language and there are hundreds of scripts out there. The one that ChronoForms uses by default is an adaptation of 'Really Easy Validation' by Andrew Tetlaw (Dexagogo), this uses the MooTools 1.1 JavaScript library that is installed by Joomla 1.5 by default. The original version of Andrew's script is for the Prototype library that is the second option for ChronoForms but best used with Joomla 1.0.

Andrew's script is good and pretty flexible. I think that there are some flaws in the MooTools adaptation that limit some of the options though. I found a better adaptation by clientcide but that uses the newer MooTools 1.2 which is not standard in Joomla 1.5 (though expected to be in Joomla 1.6).

Bob

PS I've just updated the FAQ with more info on the Dexagogo validation script.
This topic is locked and no more replies can be posted.