I have designed my form in dreamweaver and used the code as a new form, but I have a question. I have 3 seperate textboxes for phone number. Having the errors after each text box is breaking my layout badly, it looks really bad displaying them this way, so I'd like to group them and only show underneath all 3 boxes. Is this possible? You can see my form here http://www.vickiesangelwalk.org/joomla15/index.php?option=com_content&view=article&catid=31&id=49&Itemid=16
Thanks.
Thanks.
Hi,
You could use the "Show my own divs" Validation message type. That way, you're in full control where the error is displayed. Simply add a div-tag with the error message to be shown, and give it an id like "CF_LV_ERROR_inputid", and style like "display: none;".
/Fredrik
You could use the "Show my own divs" Validation message type. That way, you're in full control where the error is displayed. Simply add a div-tag with the error message to be shown, and give it an id like "CF_LV_ERROR_inputid", and style like "display: none;".
/Fredrik
If I do a display:none, then the error doesn't show up at all, even if I leave the field blank. I take it I need to use the class="required validate-alpha" in order to validate it? Here is the code I have for 1 field, and the css.
And the css for .error is just display:none. When I put my cursor in that field and tab to the next field, I don't see my error message displayed.
Thanks
<label for="organization"><span class="required">*</span>Organization Name:</label>
<input type="text" id="organization" name="organization" tabindex="1" value="" title="Please enter your organization" class="required validate-alpha"><div class="error CF_LV_ERROR_organization">Please enter your organization</div>
And the css for .error is just display:none. When I put my cursor in that field and tab to the next field, I don't see my error message displayed.
Thanks
Hi,
Actually, you need the id property to be CF_LV_ERROR_organization, not the class.
/Fredrik
Actually, you need the id property to be CF_LV_ERROR_organization, not the class.
/Fredrik
got it, thanks. Is there any documentation that shows all the validation code that should be entered for validating the fields? Meaning, a list that shows these:
class="required validate-alpha"
I assume I need to put that on my input field in order to validate that input fieled.
Thanks again!
class="required validate-alpha"
I assume I need to put that on my input field in order to validate that input fieled.
Thanks again!
Hi,
Since this part is a complement to the LiveValidation, you won't find any mentioning of this in the LiveValidation documentations. The various available validations should be the same set that you'll find on the Validation tab in the form setup. If you feel adventurous, you could read through the js/jsvalidation.js javascript, which contains the actual code for adding the validation-events based on their classes.
/Fredrik
Since this part is a complement to the LiveValidation, you won't find any mentioning of this in the LiveValidation documentations. The various available validations should be the same set that you'll find on the Validation tab in the form setup. If you feel adventurous, you could read through the js/jsvalidation.js javascript, which contains the actual code for adding the validation-events based on their classes.
/Fredrik
Is there a way to have a minimum size value on a field, for example, to validate that the phone number area code has 3 numbers? I'm using the class="required validate-numeric", but that doesn't check the size, obviously.
Thanks!
Thanks!
Hi,
I think you'll need to add some custom validations for that. You could probably still make good use of the LiveValidation-library, but you'll have to add the hooks by hand (think there's a few good examples lurking on the forum covering this, the livevalidation website is also a good resource).
/Fredrik
I think you'll need to add some custom validations for that. You could probably still make good use of the LiveValidation-library, but you'll have to add the hooks by hand (think there's a few good examples lurking on the forum covering this, the livevalidation website is also a good resource).
/Fredrik
Ok, I've put some server side validation for some of my fields. I have the below code in the server side validation box:
In my form html, I have this to show an error after the field (I'm only posting one field where I want to show the error so the post isn't too long)
If I don't enter anything in my organization field, I don't get an error displayed on the screen. Should this work the way I have it?
Thanks
<?php
function my_validate_email($email) {
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) {
return 0;
} else {
return 1;
}
}
?>
<?php
$err_cnt = 0;
//verify organization
if (!strlen(trim($_POST['organization']))) {
$err_organization="Please enter your organization name";
$err_cnt++;
//return 'Please enter your organization name';
}
//verify contact_first_name
if (!strlen(trim($_POST['contact_first_name']))) {
$err_contact_first_name="Please enter your contact first name";
$err_cnt++;
//return 'Please enter your contact first name';
}
//verify contact_last_name
if (!strlen(trim($_POST['contact_last_name']))) {
$err_contact_last_name="Please enter your contact lastname";
$err_cnt++;
//return 'Please enter your contact last name';
}
//verify contact_email
if (!strlen(trim($_POST['contact_email']))) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter your contact last name';
} else {
if (!my_validate_email($_POST['email'])) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter a valid email address';
}
//verify phone length
$phone_number = $_POST['phone_number_area_code'] + $_POST['phone_number1'] + $_POST['phone_number2'];
if (! preg_match('/^0\d{9}$/', $phone_number)) {{
$err_contact_phone_number="Please enter a 10 digit contact phone number";
$err_cnt++;
//return 'Your phone number must be 10 digits.';
}
if ($err_cnt > 0) {
return false;
} else {
return true;
}
?>
In my form html, I have this to show an error after the field (I'm only posting one field where I want to show the error so the post isn't too long)
<input type="text" id="organization" name="organization" tabindex="1" value="" title="Please enter your organization"><br /><?php if (strlen($err_organization)) {?><div class="error">$err_organization</div><?php } ?>
If I don't enter anything in my organization field, I don't get an error displayed on the screen. Should this work the way I have it?
Thanks
Hi,
Only the organization field has this problem or other fields as well ?
Max
Only the organization field has this problem or other fields as well ?
Max
all the other fields I have validaion set up for. Here is all of my validation code:
<?php
function my_validate_email($email) {
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.
'@'.
'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.
'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) {
return 0;
} else {
return 1;
}
}
?>
<?php
$err_cnt = 0;
//verify organization
if (!strlen(trim($_POST['organization']))) {
$err_organization="Please enter your organization name";
$err_cnt++;
//return 'Please enter your organization name';
}
//verify contact_first_name
if (!strlen(trim($_POST['contact_first_name']))) {
$err_contact_first_name="Please enter your contact first name";
$err_cnt++;
//return 'Please enter your contact first name';
}
//verify contact_last_name
if (!strlen(trim($_POST['contact_last_name']))) {
$err_contact_last_name="Please enter your contact lastname";
$err_cnt++;
//return 'Please enter your contact last name';
}
//verify contact_email
if (!strlen(trim($_POST['contact_email']))) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter your contact last name';
} else {
if (!my_validate_email($_POST['email'])) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter a valid email address';
}
//verify phone length
$phone_number = $_POST['phone_number_area_code'] + $_POST['phone_number1'] + $_POST['phone_number2'];
if (! preg_match('/^0\d{9}$/', $phone_number)) {{
$err_contact_phone_number="Please enter a 10 digit contact phone number";
$err_cnt++;
//return 'Your phone number must be 10 digits.';
}
if ($err_cnt > 0) {
return false;
} else {
return true;
}
?>
Thanks!
Ok, try to replace this:
with:
let me know!
<div class="error">$err_organization</div>
with:
<div class="error"><?php echo $err_organization; ?></div>
let me know!
Ok, I updated my code, but i can still submit the form and it goes to the thank you message, no errors displayed.
Please change this bit of code:
to
if ($err_cnt > 0) {
return false;
} else {
return true;
}
to
if ($err_cnt > 0) {
return "Some errors occurred, please review the form below:";
} else {
//return true;
}
Nope, i can still submit my form and see the thank you message, no errors. here is a link if you want to see my page code:
http://www.vickiesangelwalk.org/joomla15/index.php?option=com_content&view=article&catid=31&id=49&Itemid=16
Thanks!!!
http://www.vickiesangelwalk.org/joomla15/index.php?option=com_content&view=article&catid=31&id=49&Itemid=16
Thanks!!!
Any luck with getting this to work? I really appreciate all the help provided so far.
Thanks!!
Thanks!!
Hi jrthor,
you had a syntax error in your main validation code and it would not work anyway, please test with this one, I fixed few issues:
Regards,
Max
you had a syntax error in your main validation code and it would not work anyway, please test with this one, I fixed few issues:
<?php
function my_validate_email($email) {
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) {
return 0;
} else {
return 1;
}
}
?>
<?php
$err_cnt = 0;
//verify organization
if (!strlen(trim($_POST['organization']))) {
$err_organization="Please enter your organization name";
$err_cnt++;
//return 'Please enter your organization name';
}
//verify contact_first_name
if (!strlen(trim($_POST['contact_first_name']))) {
$err_contact_first_name="Please enter your contact first name";
$err_cnt++;
//return 'Please enter your contact first name';
}
//verify contact_last_name
if (!strlen(trim($_POST['contact_last_name']))) {
$err_contact_last_name="Please enter your contact lastname";
$err_cnt++;
//return 'Please enter your contact last name';
}
//verify contact_email
if (!strlen(trim($_POST['contact_email']))) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter your contact last name';
}
if (!my_validate_email($_POST['email'])) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter a valid email address';
}
//verify phone length
$phone_number = $_POST['phone_number_area_code'] + $_POST['phone_number1'] + $_POST['phone_number2'];
if (! preg_match('/^0\d{9}$/', $phone_number)) {
$err_contact_phone_number="Please enter a 10 digit contact phone number";
$err_cnt++;
//return 'Your phone number must be 10 digits.';
}
if ($err_cnt > 0) {
return false;
} else {
return true;
}
?>
Regards,
Max
I just replaced my validation code with yours, and I left my form blank and was able to submit it. Still no errors showing.
I didn't say it will work, only fixed few errors, I have went through it now and made some changes so it can work, this is the validation code, I have only fixed the organization entry:
and thats how it looks like now in the html:
Cheers,
Max
<?php
function my_validate_email($email) {
if (!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $email)) {
return 0;
} else {
return 1;
}
}
?>
<?php
$err_cnt = 0;
//verify organization
if (!strlen(trim($_POST['organization']))) {
JRequest::setVar('err_organization', "Please enter your organization name");
$err_cnt++;
//return 'Please enter your organization name';
}
//verify contact_first_name
if (!strlen(trim($_POST['contact_first_name']))) {
$err_contact_first_name="Please enter your contact first name";
$err_cnt++;
//return 'Please enter your contact first name';
}
//verify contact_last_name
if (!strlen(trim($_POST['contact_last_name']))) {
$err_contact_last_name="Please enter your contact lastname";
$err_cnt++;
//return 'Please enter your contact last name';
}
//verify contact_email
if (!strlen(trim($_POST['contact_email']))) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter your contact last name';
}
if (!my_validate_email($_POST['email'])) {
$err_contact_email="Please enter your contact email address";
$err_cnt++;
//return 'Please enter a valid email address';
}
//verify phone length
$phone_number = $_POST['phone_number_area_code'] + $_POST['phone_number1'] + $_POST['phone_number2'];
if (! preg_match('/^0\d{9}$/', $phone_number)) {
$err_contact_phone_number="Please enter a 10 digit contact phone number";
$err_cnt++;
//return 'Your phone number must be 10 digits.';
}
if ($err_cnt > 0) {
return 'your form has some errors:';
} else {
//return true;
}
?>
and thats how it looks like now in the html:
<input type="text" id="organization" name="organization" tabindex="1" value="" title="Please enter your organization"><br /><?php if (JRequest::getVar('err_organization', '')) {?><div class="error"><?php echo JRequest::getVar('err_organization', ''); ?></div><?php } ?>
Cheers,
Max
Hi again,
Wouldn't PHP's type conversion break the following test?:
I guess you intended to concatenate the strings and see if there's 10 digits in it, however, using the ADD operator (+) would force PHP to typecast the values into numbers and add them. I'd suggest using the concatenation operator (.) instead.
Also, if you return true/false, keep in mind that false would be the same as an empty string (validation successful), while any non-empty string would be true (validation failed).
/Fredrik
Wouldn't PHP's type conversion break the following test?:
$phone_number = $_POST['phone_number_area_code'] + $_POST['phone_number1'] + $_POST['phone_number2'];
I guess you intended to concatenate the strings and see if there's 10 digits in it, however, using the ADD operator (+) would force PHP to typecast the values into numbers and add them. I'd suggest using the concatenation operator (.) instead.
Also, if you return true/false, keep in mind that false would be the same as an empty string (validation successful), while any non-empty string would be true (validation failed).
/Fredrik
Wow, thank you soooooo much. It appears to be working now. Yeah, i fixed the + signs to ".". I do programming in Java all day, and the concatenation string in java is a + sign.
Thanks again so much!!!
Thanks again so much!!!
Well, maybe I spoke too soon. I have my form completed, and all the validation seems to work when I click on the link for my form from the Forms Management screen. But, if I go to my article that I have the form embedded in, I get the error at the very top that says "Please fix the below errors", but none of my errors are displayed under the input boxes. Now what's wrong?? I've attached a screen shot.
Thanks
Thanks
any suggestions as to why my the page works correctly if I click the link to the page from the Forms Management screen, but when the form is inside an article, it's not working the same way?
thanks!!
thanks!!
Hi jrthor2,
No I don't have any useful suggestions, sorry.
The error message looks like a server-side validation message - it's not a typical LiveValidation message.
It's possible that there is some bug in the Plugincode- but I don't remember one being reported like this.
The easy answer is probably not to embed the form in an article. Do you need to do this - it looks pretty stand-alone to me?
Bob
No I don't have any useful suggestions, sorry.
The error message looks like a server-side validation message - it's not a typical LiveValidation message.
It's possible that there is some bug in the Plugincode- but I don't remember one being reported like this.
The easy answer is probably not to embed the form in an article. Do you need to do this - it looks pretty stand-alone to me?
Bob
Hi again,
As I roughly recall, the Mambot/plugin does a $mainframe->redirect in the event of a form error, so that the Article URI and Content are properly displayed. This, unfortunately, has the side-effect of "wiping" anything stored in the $_POST superglobal.
Best way around this, which would work regardless how the form is displayed, would be to make use of the session storage. Especially, this is how the error message(s) are preserved by CF/plugin in case of an error condition.
Something like this should do the trick;
SSValidation:
And form code:
The code is written from memory, but untested. Please let me know how it works out.
/Fredrik
As I roughly recall, the Mambot/plugin does a $mainframe->redirect in the event of a form error, so that the Article URI and Content are properly displayed. This, unfortunately, has the side-effect of "wiping" anything stored in the $_POST superglobal.
Best way around this, which would work regardless how the form is displayed, would be to make use of the session storage. Especially, this is how the error message(s) are preserved by CF/plugin in case of an error condition.
Something like this should do the trick;
SSValidation:
<?
$session =& JFactory::getSession();
...
if (!strlen(trim($_POST['organization']))) {
$session->set('errordetails_organization', 'Please enter your organization name', md5('chronoerror'));
$err_cnt++;
//return 'Please enter your organization name';
}
And form code:
<?
$session = JFactory::getSession();
?>
...
<input type="text" id="organization" name="organization" tabindex="1" value="" title="Please enter your organization" /><br /><?
if ($errCond = $session->get('errordetails_organization', false, md5('chronoerror'))) {
echo '<div class="error">' . $errCond . '</div>';
}
$session->clear('errordetails_organization', md5('chronoerror'));
?>
The code is written from memory, but untested. Please let me know how it works out.
/Fredrik
Ok, I have 1 issue with this updated validation code. It works fine, except for my email field. If I get an error on any of my fields, the email that shows in my email input field is below, some sort of javascript.
How is this fixed?
Thanks!!
<script language='JavaScript' type='text/javascript'> <!-- var prefix = 'ma' + 'il' + 'to'; var path = 'hr' + 'ef' + '='; var addy17187 = 'test' + '@'; addy17187 = addy17187 + 'test' + '.' + 'com'; document.write( '<a ' + path + '\'' + prefix + ':' + addy17187 + '\'>' ); document.write( addy17187 ); document.write( '<\/a>' ); //-->\n </script> <script language='JavaScript' type='text/javascript'> <!-- document.write( '<span style=\'display: none;\'>' ); //--> </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it <script language='JavaScript' type='text/javascript'> <!-- document.write( '</' ); document.write( 'span>' ); //--> </script>
How is this fixed?
Thanks!!
Hi,
That's due to the email cloaking systems plugin/mambot. There's a few posts lying around here that covers this, but simply put, either disable that plugin, or make sure it has a higher (or was it lower) priority than the chronoforms plugin.
/Fredrik
That's due to the email cloaking systems plugin/mambot. There's a few posts lying around here that covers this, but simply put, either disable that plugin, or make sure it has a higher (or was it lower) priority than the chronoforms plugin.
/Fredrik
Cool, thanks. The email cloaking plug-in should be less than the chronocontact plug-in.
One last question (I hope) dealing with my phone numbers. If I have 3 input boxes for the phone number, is it possible to store these 3 values in the database in 1 column, and not 3 separate columns, like 123-456-7890?
thanks again!
One last question (I hope) dealing with my phone numbers. If I have 3 input boxes for the phone number, is it possible to store these 3 values in the database in 1 column, and not 3 separate columns, like 123-456-7890?
thanks again!
Hi jrthor2,
Yes, use the OnSubmit Before box to combine them into a single input. There are several examples in the forms - mostly combining first name and last name.
Bob
Yes, use the OnSubmit Before box to combine them into a single input. There are several examples in the forms - mostly combining first name and last name.
Bob
Ok, I have this in OnSubmit before
And this in my form:
And I added a field to my database to store this value, but how do I get it into the database? I filled out my form, but the phone_number column was blank.
I also added this field and field type (text) to the end of the Form Field Names in the AutoGenerated tab (not sure I need this or not)
Thanks
<?php
$_POST['phone_number'] = $_POST['phone_number_area_code'] & "-" & $_POST['phone_number1'] & "-" & $_POST['phone_number2'];
?>
And this in my form:
<input type="hidden" name="phone_number" value="" />
And I added a field to my database to store this value, but how do I get it into the database? I filled out my form, but the phone_number column was blank.
I also added this field and field type (text) to the end of the Form Field Names in the AutoGenerated tab (not sure I need this or not)
Thanks
Hi jrthor2,
That should work OK (I would have used the Joomla JRequest::getVar() and setVar() methods but otherwise the same).
If you add a column to the dataabase table (or make any other similar change) you need to refresh the database connection. Go to the DB Connection tab, set the connection to No, apply or save the form; go back to the DB Connection tab, set the connection to Yes and apply or save again.
ChronoForms saves a list of the table columns (actually a JTable class) used for the save in the database and this is the only way I know of updating it.
Bob
That should work OK (I would have used the Joomla JRequest::getVar() and setVar() methods but otherwise the same).
If you add a column to the dataabase table (or make any other similar change) you need to refresh the database connection. Go to the DB Connection tab, set the connection to No, apply or save the form; go back to the DB Connection tab, set the connection to Yes and apply or save again.
ChronoForms saves a list of the table columns (actually a JTable class) used for the save in the database and this is the only way I know of updating it.
Bob
Could you give me an example of what you mean by using the Joomla JRequest::getVar() and setVar() methods? I followed the directions found in one of your posts for combining fields, so that's wy I did it the way I did.
Thanks for the great help!!
Thanks for the great help!!
Hi jrthor2,
Joomla provides some code for accessing the variables from the $_REQUEST arrays (post, get, cookie) that includes some input filtering and so is a bit more secure than accessing the arrays directly.
The main functions are:
The equivalent for writing values is
So in long form your code would look like
Bob
Joomla provides some code for accessing the variables from the $_REQUEST arrays (post, get, cookie) that includes some input filtering and so is a bit more secure than accessing the arrays directly.
The main functions are:
$param = JRequest::getVar('param_name', 'default_value, 'source');
where you can replace getVar with e.g. getString, getInt, getCmd, getWord, to add more validation. (See the full method list here).The equivalent for writing values is
JRequest::setVar('param_name', $param_value);
So in long form your code would look like
<?php
$area_code = JRequest::getInt('phone_number_area_code', '', 'post');
$phone1 = JRequest::getInt('phone_number1', '', 'post');
$phone2 = JRequest::getInt('phone_number2', '', 'post');
$phone_number = $area_code."-".$phone1."-".$phone2;
JRequest::setVar('phone_number', $phone_number, 'post');
?>
though I'd more likely write something along these lines<?php
$phone_array = array('phone_number_area_code' => '', 'phone_number1' => '' => '', 'phone_number2');
foreach ( $phone_array as $k => $v ) {
$phone_array[$k] = JRequest::getInt($k, '', 'post');
}
JRequest::setVar('phone_number', implode('-', $phone_array), 'post');
?>
Bob
This topic is locked and no more replies can be posted.