Mibew Messenger Community
Contributions => Plugins, tips, and tricks => Topic started by: bobscan on November 20, 2012, 07:20:54 PM
-
#######################################################
Fix survey blank/bad input #
#######################################################
There's pre-existing functionality of leavemessage.php's validation methods, which requires input, and requiring a properly formed email address.
thankfully, we can easily integrate this into our pre-chat survey.
insert this @ line 80 of a distro-default client.php. (append it as part of the 'if survey is on' function, just before the following }else{ clause)
$errors = NULL;
if( !$email ) {
$errors[] = no_field("form.field.email");
} else if( !$newname ) {
$errors[] = no_field("form.field.name");
} else if( !$firstmessage ) {
$errors[] = no_field("form.field.message");
} else {
if( !is_valid_email($email)) {
$errors[] = wrong_field("form.field.email");
}
}
then insert at line 115, now 128 if you added the above statement. (following the 'IP connections exceeded' clause, and before $thread string definition)
if( count($errors) > 0 ){
$page = array();
setup_logo();
setup_survey($visitor['name'], $email, $groupid, $info, $referrer);
expand("styles", getchatstyle(), "survey.tpl");
exit;
}
-
Just wanted to update this for the current version of Mibew (1.6.9)
The provided code does still work perfectly, BUT the line numbers are different, and I also added my own touch.
In the root Mibew folder, open client.php.
The following code now gets added right after line 86. (after the userchangename function.)
$errors = NULL;
if( !$email ) {
$errors[] = no_field("form.field.email");
} else if( !$newname ) {
$errors[] = no_field("form.field.name");
} else if( !$firstmessage ) {
$errors[] = no_field("form.field.message");
} else {
if( !is_valid_email($email)) {
$errors[] = wrong_field("form.field.email");
}
}
After adding that, this second block of code goes right after line 141. (after the check multiple IP function.)
if( count($errors) > 0 ){
$page = array();
setup_logo();
setup_survey($visitor['name'], $email, $groupid, $info, $referrer);
expand("styles", getchatstyle(), "survey.tpl");
exit;
}
Not so different so far, BUT what the original author didn't consider is that the form auto-fills, at least in my case, the word 'Guest' as a placeholder. The problem there is that 'Guest' passes the validation! D'oh! But no worries, there is a super simple solution. Bby the way, this applies specifically to the English localization, but probably also applies to other languages as well.
Open mibew/locales/en/properties (note the lack of an extension, make sure your editor doesn't add an extension when saving!)
On line 44, find:
chat.default.username=Guest
and change it to:
chat.default.username=
This keeps it from auto-filling the word 'guest', and forces the user to enter SOMETHING.
Otherwise the original poster had it all perfect for his version of Mibew, and I am just adapting it to my needs. I was getting driven crazy by people entering guest and talking to us as if we knew who they were, such as: "Did my order ship?" and we would have to always ask them to identify themselves.
-
I don't know why people don't bother to say THANK YOU for some one putting so much of efforts for others. Seriously man, thanks a lot for this solution you have posted. Just one doubt I have, on the chat window at NAME field it keep saying Please fill "Your email". Is there any way to force just a normal name
-
:o not a programmer but figured out.
Instead of
$errors = NULL;
if( !$email ) {
$errors[] = no_field("form.field.email");
} else if( !$newname ) {
$errors[] = no_field("form.field.name");
} else if( !$firstmessage ) {
$errors[] = no_field("form.field.message");
} else {
if( !is_valid_email($email)) {
$errors[] = wrong_field("form.field.email");
}
}
Just use
$errors = NULL;
if( !$newname ) {
$errors[] = no_field("form.field.name");
this is only if you do not want visitors to enter their email on first window of chat.
-
I want to insert my two cents.
It would be better to use
$errors = array();
instead of $errors = NULL;
to avoid PHP notices.
-
to improve the validation of email common.php file and go to the regular expression to replace the line 563 for this.
original (validate client@mibew like correct) line 563
return preg_match("/^[^@]+@[^\.]+(\.[^\.]+)*$/", $email);
Replace for this (now validate client@mibew like wrong the correct email is client@mibew.org)
return preg_match("/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/", $email);
-
to function properly in the verification form entry to chat in version 1.6.11 should add the following code at line 87 of client.php
/*newcode*/
$errors = array();
if( !$email ) {
$errors[] = no_field("presurvey.mail");
} else if( !$newname ) {
$errors[] = no_field("presurvey.name");
} else if( !$firstmessage ) {
$errors[] = no_field("presurvey.question");
} else {
if( !is_valid_email($email)) {
$errors[] = wrong_field("presurvey.mail");
}
}
/*end this code*/
if( count($errors) > 0 ){
$page = array();
setup_logo();
setup_survey($visitor['name'], $email, $groupid, $info, $referrer, can_show_captcha());
expand("styles", getchatstyle(), "survey.tpl");
exit;
}
/*###########*/
-
to function properly in the verification form entry to chat in version 1.6.11 should add the following code at line 87 of client.php
/*newcode*/
$errors = array();
if( !$email ) {
$errors[] = no_field("presurvey.mail");
} else if( !$newname ) {
$errors[] = no_field("presurvey.name");
} else if( !$firstmessage ) {
$errors[] = no_field("presurvey.question");
} else {
if( !is_valid_email($email)) {
$errors[] = wrong_field("presurvey.mail");
}
}
/*end this code*/
if( count($errors) > 0 ){
$page = array();
setup_logo();
setup_survey($visitor['name'], $email, $groupid, $info, $referrer, can_show_captcha());
expand("styles", getchatstyle(), "survey.tpl");
exit;
}
/*###########*/
How can I apply this in Mibew 2?