Hi Max,
I am using the latest version of Chronoform and somehow I am having trouble including a custom server side validation in the form. My custom php validation in the radio button is not working. If I can get the right input on how to use the php validation in the latest version, I will appreciate it. I am trying to validate if the radio button selected is equal to "Other" then the textbox should not be empty and vice versa but it is not working when I include the validation to the VAlidation tab/Enable Server side validation = Yes/Server side validation code. Below is my code for html and validation. Please advice how to write it if it is wrong. Thanks.
Here is my custom php validation for the radio button and textbox.
I ham new in this version which is totally different from the 2.1 version because the php validation I included in the old version doesn't work here. Hope you can help me as soon as possible. Thanks.
I am using the latest version of Chronoform and somehow I am having trouble including a custom server side validation in the form. My custom php validation in the radio button is not working. If I can get the right input on how to use the php validation in the latest version, I will appreciate it. I am trying to validate if the radio button selected is equal to "Other" then the textbox should not be empty and vice versa but it is not working when I include the validation to the VAlidation tab/Enable Server side validation = Yes/Server side validation code. Below is my code for html and validation. Please advice how to write it if it is wrong. Thanks.
<div class="form_item">
<div class="form_element cf_text"> <span class="cf_text">Please specify the amount of money you would like to give.</span> </div>
<div class="cfclear"> </div>
</div>
<div class="form_item">
<div class="form_element cf_radiobutton">
<label class="cf_label" style="display: none;">Click Me to Edit</label>
<div class="float_left">
<input value="$25" title="" class="radio validate-one-required" id="radio00" name="radio0" type="radio" />
<label for="radio00" class="radio_label">$25</label>
<input value="$50" title="" class="radio validate-one-required" id="radio01" name="radio0" type="radio" />
<label for="radio01" class="radio_label">$50</label>
<input value="$100" title="" class="radio validate-one-required" id="radio02" name="radio0" type="radio" />
<label for="radio02" class="radio_label">$100</label>
<input value="$250" title="" class="radio validate-one-required" id="radio03" name="radio0" type="radio" />
<label for="radio03" class="radio_label">$250</label>
<input value="$500" title="" class="radio validate-one-required" id="radio04" name="radio0" type="radio" />
<label for="radio04" class="radio_label">$500</label>
<input value="$750" title="" class="radio validate-one-required" id="radio05" name="radio0" type="radio" />
<label for="radio05" class="radio_label">$750</label>
<input value="$750" title="" class="radio validate-one-required" id="radio06" name="radio0" type="radio" />
<label for="radio06" class="radio_label">$750</label>
<br />
<input value="Other" title="" class="radio validate-one-required" id="radio07" name="radio0" type="radio" />
<label for="radio07" class="radio_label">Other</label>
<label class="cf_label" style="display: none;">Click Me to Edit</label>
<input class="cf_inputbox validate-currency-dollar" maxlength="150" size="30" title="Enter dollar amount here" id="text_7" name="donate_amount_other" type="text" />
</div>
</div>
</div>
Here is my custom php validation for the radio button and textbox.
<?php
$messages = array();
$radio0 = JRequest::getString('radio0', '', 'post');
if (!$radio0) {
$messages[] = "One selection is required";
}
if ($_POST['radio0'] == 'Other') {
if (empty($donate_amount_other)){
return 'You selected Other, please enter amount to donate in the textbox to avoid errors';
} else {
$_POST['radio0'] == 'Other';
}
}
//check if there are any error messages and return
if(count$messages) ) {
return implode('<br />', $messages);
}
?>
I ham new in this version which is totally different from the 2.1 version because the php validation I included in the old version doesn't work here. Hope you can help me as soon as possible. Thanks.
Hi jmarian1,
You have the variable $donate_amount_other in the code but it isn't defined anywhere. Here's a modified version of the code:
Bob
You have the variable $donate_amount_other in the code but it isn't defined anywhere. Here's a modified version of the code:
<?php
$messages = array();
$radio0 = JRequest::getString('radio0', '', 'post');
$donate_amount_other = JRequest::getString('donate_amount_other', '', 'post');
if ( !$radio0 ) {
$messages[] = "One selection is required";
} elseif ( $radio0 == 'Other' && !$donate_amount_other ) {
$messages[] 'You selected Other, please enter amount to donate in the textbox to avoid errors';
}
//check if there are any error messages and return
if ( count$messages ) ) {
return implode('<br />', $messages);
}
?>
Bob
Hi Bob,
Thanks for the revised version but somehow I tried your code and still the validation doesn't work. It still allow to go to the next step if Other is selected without the $$$ amount entered. I am not sure if there is something wrong with the code or the chronoform itself. Please advice. Thanks.
Thanks for the revised version but somehow I tried your code and still the validation doesn't work. It still allow to go to the next step if Other is selected without the $$$ amount entered. I am not sure if there is something wrong with the code or the chronoform itself. Please advice. Thanks.
This topic is locked and no more replies can be posted.