Hi Bob/Max. I need help in the CSSV. I am not sure if it is the CSSV that is not working or my code. I have a drop down list that I need to validate based on the data entered in the textbox but somehow the CSSV validation doesn't work. The validation below just bypass and go straight to the next page if I selected Category=1-999 and entered a project cost = 8888, which I dont want to happen. I also have a validation to check if the login user already entered the category he selected in the first page. Please help. I am stuck on this and I need to fix it as soon as possible. Attached is my form. Thanks in advance.
My validations that are not working:
1. the Category Level selected should not be less than or greater than the number in each level
2. if category selected exist in database, principal should not allow to enter the same category. (ie.
Somehow, the validation below is not working in the CSSV. It is bypassing it and go straight to the Thank You message. I am using the multi page form in v4. PLease help. I really need this to work as soon as possible. Thanks.
My HTML code for category and project_cost
My validations that are not working:
1. the Category Level selected should not be less than or greater than the number in each level
2. if category selected exist in database, principal should not allow to enter the same category. (ie.
1. Category: 1-999 should not be less than 1 or equal to 999 in the project_cost.
2. once the user selected a category, I want to check if the registered user already entered the category level to the database. If the user does, return an alert message and will not allow them to enter the same category.
Somehow, the validation below is not working in the CSSV. It is bypassing it and go straight to the Thank You message. I am using the multi page form in v4. PLease help. I really need this to work as soon as possible. Thanks.
<?php
$error_exists = false;
$category_code = JRequest::getString('category_code', '', 'post');
$project_cost = JRequest::getString('project_cost', '', 'post');
//check if category level and project cost is equal
if ($category_code == "1-999" && $project_cost < 1 && $project_cost > 999)
{
$form->validation_errors['project_cost'] = 'You selected Level 1: $1-$999 in the Category Level. Project estimated cost amount should not be less than $1.00 and greater than $999.00. Please revise your entry or use the right Category Code.';
$error_exists = true;
}
elseif ($category_code == "1000-9999" && $project_cost < 1000 && $project_cost > 9999)
{
$form->validation_errors['project_cost'] = 'You selected Level 2 in the Category Level. Project estimated cost amount should not be less than $1,000 and greater than $9,999.00. Please revise your entry or use the right Category Code.';
$error_exists = true;
}
elseif ($category_code == "10000-99999" && $project_cost < 10000 && $project_cost > 99999)
{
$form->validation_errors['project_cost'] = 'You selected Level 3 in the Category Level. Project estimated cost amount should not be less than $10,000 and greater than $99,999.00. Please revise your entry or use the right Category Code.';
$error_exists = true;
}
elseif ($category_code == "250000plus" && $project_cost < 250000)
{
$form->validation_errors['project_cost'] = 'You selected the Dream Project in the Category Level. Project estimated cost amount should not be less than $250,000. Please revise your entry or use the right Category Code.';
$error_exists = true;
}
// Get user object -information from Joomla
$user= JFactory::getUser();
$name=$user->name;
$db =& JFactory::getDBO();
$query = "
SELECT `name`, `category_code`
FROM `#__chronoforms_data_principal_project`
WHERE `name` = '{$name}' && `category_code` = '{$category_code}'";
$db->setQuery($query);
$data = $db->loadResult();
if ($data) {
return 'Sorry, the Category you selected already exists in the database. You are allowed to enter only one project for each category.';
print_r ($data);
$error_exists = true;
}
return !$error_exists;
?>
My HTML code for category and project_cost
<div class="formfield" id="autoID-a4668c617f57df750cb17fca9d17796b_container_div">
<label for="category_code">Category Code:</label>
<select size="1" id="category_code" class=" validate['required']" title="" name="category_code">
<option value="">Category is required.</option>
<option value="" selected="selected">Select Category</option>
<option value="1-999">Level 1: $1-$999</option>
<option value="1000-9999">Level 2: $1,000-$9,999</option>
<option value="10000-99999">Level 3: $10,000-$99,999</option>
<option value="250000plus">Dream Project: $250,000+</option>
</select>
<div class="clear"></div>
<div id="error-message-category_code"></div>
</div>
<div class="formfield" id="autoID-7d8a4d57407a7db380e5a6fd7035e92c_container_div">
<label for="project_cost">Project Estimated Cost: $</label><input id="project_cost" maxlength="150" size="30" class=" vvalidate['required','digit','number']" title="" type="text" value="" name="project_cost" />
<div class="clear"></div>
<div id="error-message-project_cost"></div>
</div>
Hi jmarian1,
Looking at your backup form the ChronoForms settings look OK so this it probably a problem with your code. You have quite a complicated sequence of tests there and you will need to debug step by step. Probably the easiest way is to temporarily comment out all but one so that you can check the code for the one that is left active.
Bob
Looking at your backup form the ChronoForms settings look OK so this it probably a problem with your code. You have quite a complicated sequence of tests there and you will need to debug step by step. Probably the easiest way is to temporarily comment out all but one so that you can check the code for the one that is left active.
Bob
Hi Bob, following your suggestion, the validation in my textboxes and textarea works fine. However, checking the database for principal user if exist in the database is not working.
Ok, I eliminated my code and follow the code from the Cookbook below to make sure that there is nothing wrong and somehow it's not giving me anything. It just bypass and go straight to the thank you message. Please help. I really need this to work.
My CSSV:
Ok, I eliminated my code and follow the code from the Cookbook below to make sure that there is nothing wrong and somehow it's not giving me anything. It just bypass and go straight to the thank you message. Please help. I really need this to work.
My CSSV:
<?php
//validate if principal tries to enter the same category
$principal_name = JRequest::getString('principal_name', '', 'post');
$category_code = JRequest::getString('category_code', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT `principal_name`, `category_code`
FROM `#__chronoforms_data_principal_project`
WHERE `principal_name` = '{$principal_name}' && `category_code` = '{$category_code}'";
$db->setQuery($query);
$data = $db->loadObjectList();
if ($data) {
return 'Sorry, the Category you selected already exists in the database. You are allowed to enter only one project for each category.';
print_r ($data);
}
?>
Hi jmarian1,
Yes but the Cookbook code was for ChronoForms v3 and won't necessarily work in ChronoForms v4.
In CFV4 your Serverside test needs to set a message and return false as it did in the previous example. See here
Bob
PS I've changed the way I code multiple tests now to make it a bit clearer:
Yes but the Cookbook code was for ChronoForms v3 and won't necessarily work in ChronoForms v4.
In CFV4 your Serverside test needs to set a message and return false as it did in the previous example. See here
$form->validation_errors['project_cost'] = 'You selected the Dream Project in the Category Level. Project estimated cost amount should not be less than $250,000. Please revise your entry or use the right Category Code.';
$error_exists = true;
}
return !$error_exists;
Bob
PS I've changed the way I code multiple tests now to make it a bit clearer:
<?php
$valid = true;
if ( . . . some test . . . ) {
$form->validation_errors['...'] = "...";
$valid =false;
}
if ( . . . some test . . . ) {
$form->validation_errors['...'] = "...";
$valid =false;
}
return $valid;
?>
Hi Bob,
Thank you so much for your help and patient. It works like a charm. Thank you!!!!! God bless!
Thank you so much for your help and patient. It works like a charm. Thank you!!!!! God bless!
Hi Bob,
One quick question please, I noticed that my error message with $sign is not showing. See error below. Why it doesn't show the $ sign and number? Everything works good except below. Please help. Thanks.
[attachment=0]Screen Shot 2012-02-26 at 1.41.00 PM.png[/attachment]
Supposed to be, the error message is "You selected Level 1 in the Category Level. Project estimated cost amount should not be less than $1 and greater than $999. Please revise your entry or use the right Category Code."
One quick question please, I noticed that my error message with $sign is not showing. See error below. Why it doesn't show the $ sign and number? Everything works good except below. Please help. Thanks.
[attachment=0]Screen Shot 2012-02-26 at 1.41.00 PM.png[/attachment]
Supposed to be, the error message is "You selected Level 1 in the Category Level. Project estimated cost amount should not be less than $1 and greater than $999. Please revise your entry or use the right Category Code."
Hi jmarian1,
Technically I think that it's because the code, including the error message, is evaluated as PHP and the $ is the PHP variable sign. The easiest fix is to use an HTML entity instead $
Bob
Technically I think that it's because the code, including the error message, is evaluated as PHP and the $ is the PHP variable sign. The easiest fix is to use an HTML entity instead $
Bob
Hi Bob,
I actually did it but no luck and just gives me the result below with I don't know what character is that.
[attachment=0]Screen Shot 2012-02-26 at 9.35.40 PM.png[/attachment]
I actually did it but no luck and just gives me the result below with I don't know what character is that.
[attachment=0]Screen Shot 2012-02-26 at 9.35.40 PM.png[/attachment]
Hi jmarian1,
The messages with $ or $ both work OK on my test site. I suggest that you check the character set that your page is using.
Bob
The messages with $ or $ both work OK on my test site. I suggest that you check the character set that your page is using.
Bob
Hi Bob, thanks for your help. Actually, the message on the top works fine. The only problem is in the bottom of each textboxes. Sorry but I don't know where to check the character set. Would you be able to guide me where can I do that? I am using joomla 1.7 what do you mean by page I am using? Please advice. Thanks.
Hi jmarian1,
The HTML entity works in both messages for me. Here's the code
I think the character set is a site or Document setting; in the defautl Joomla! template I see
Bob
The HTML entity works in both messages for me. Here's the code
<?php
$form->validation_errors['input_text_1'] = 'You selected the Dream Project in the Category Level. Project estimated cost amount should not be less than $250,000. Please revise your entry or use the right Category Code.';
return false;
?>
I think the character set is a site or Document setting; in the defautl Joomla! template I see
<meta http-equiv="content-type" content="text/html; charset=utf-8">
Bob
Hi Bob. The top error message works fine in my side like below.
[attachment=1]Screen Shot 2012-02-28 at 8.24.54 PM.png[/attachment]
However, the the number in the bottom message in the textbox itself doesn't show if the $ sign is included in the code. See below. I am using a custom html code in the form.
[attachment=0]Screen Shot 2012-02-28 at 8.51.45 PM.png[/attachment]
The message supposed to be like
By the way, I don't have the code
Please help. Thanks.
[attachment=1]Screen Shot 2012-02-28 at 8.24.54 PM.png[/attachment]
However, the the number in the bottom message in the textbox itself doesn't show if the $ sign is included in the code. See below. I am using a custom html code in the form.
[attachment=0]Screen Shot 2012-02-28 at 8.51.45 PM.png[/attachment]
The message supposed to be like
$form->validation_errors['project_cost'] = 'You selected Level 1 in the Category Level. Project estimated cost amount should not be less than $1 and greater than $1000. Please revise your entry or use the right Category Code.';
$valid =false;
By the way, I don't have the code
<meta http-equiv="content-type" content="text/html; charset=utf-8">
in my default index.php. I am using a custom template. Please help. Thanks.
Hi jamrian1,
Sorry, ChronoForms isn't very good at preserving the entity code when I copied and pasted. I had $ in the message and that is working OK here. I changed my earlier post to show it correctly.
Bob
Sorry, ChronoForms isn't very good at preserving the entity code when I copied and pasted. I had $ in the message and that is working OK here. I changed my earlier post to show it correctly.
Bob
Hi Bob. Thank you for your help. It is so strange to me but anyway, it works. Now I know why sometimes it doesn't work when I get back and add more validation or I saved the CSSV again the next time. The
$
code added to my number become$
again after I resave it, that is why it doesn't work the next time. Now, I will always remember to change the$
sign to$
everytime I made changes to my CSSV. Anyway, as long as it works, its ok for me. Thanks for your help!!This topic is locked and no more replies can be posted.