PDA

View Full Version : Validation conditionals possible?


eric341232
04-28-2009, 12:19 PM
It would be great to be able to set conditions for certain validation situations. I hope that's part of any upgrade in the future.

In the meantime, I wonder if there is any way to work conditions into scheme as is, and by conditional I mean that, for instance, a check in a "phone" checkbox would require that a phone number be entered in the phone field. A phone number would not be required if it is not checked. This sort of thing, if some form field condition is true, then some validation has to happen on some other form field, and this beyond simple comparison of what's been entered, although maybe that trigger could be jiggered.

You see what I'm getting at. Any thoughts on this?

Ray Borduin
04-28-2009, 12:22 PM
You can already do it both client and server side.

Are you doing client or server validation? What server language?

eric341232
04-28-2009, 04:05 PM
I'm using server side validation, the php variety. I don't see a conditional option. The only kind of conditional I see is "like entry."

It's certainly possible that setting up conditional validation where if, for instance, a checkbox is selected then a particular text input must have data, is available but I just don't see it.

I've got

Alphanumeric
CC number
Date/time
Email address
entry length
File extension
like entry
number
phone number
regular expression
required/not blank/selection made
restrict content
SS number
url
zip code

I must not be seeing something right in front of my face.

Ray Borduin
04-29-2009, 06:55 AM
It takes a small amount of logic and scripting within the interface to pull off.

For instance... if you are using phone number validation on a field called phoneNumber and you only want it required if a checkbox called callMe is checked.

You would use phone number validation and for the validated value you would browse to the phoneNumber field in the bindings, which would give you the value:
<?php echo((isset($_POST['phoneNumber'])?$_POST['phoneNumber']:"")); ?>

Now update it to use:
<?php echo((isset($_POST['callMe'])?$_POST['phoneNumber']:"(222) 222-2222")); ?>

This tells it to check to see if callMe was checked and if it is send the value of phoneNumber to be validated, otherwise it passes a valid phone number which would pass validation. The end result is exactly what you want.

eric341232
05-01-2009, 08:58 AM
Yes. Now that I see it, that seems right. Thank you.

Sades
02-27-2010, 09:30 PM
can i do this but not with checkbox?

I have a form to upload 6 pictures example

Thumb
pic1
pic1 big
pic2
pic2 big etc.....

i only require the thumb pic1 and pic1 big until here im ok but i want that if the user uploads a pic2 that pic2 big becomes required if he doesnt select any file for pic 2 then theres no need for pic2 big, any help if this can be done?

Ray Borduin
03-01-2010, 07:15 AM
Yes, this can be done with either client or server validation. Of course server validation is more secure since it can't be turned off.

You know if you use Digital File Pro you can have them only upload the big image and automatically create the thumb and get around the need for validation in this case as well.

Sades
09-18-2010, 10:30 PM
Came back to this post cause now im trying to do something similiar i have a check box field and some text field i only want them to be required if the checkbox is selected, i did the above explained by Ray Borduin, but it always ask me to check the checkbox in order to continue, im using server side validation wich is the one i prefer cause it cant be shut down.


<?php
if (isset($_POST["KT_Custom1"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_depositar_716_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_POST["Tipo_de_operacion"]))?$_POST["Banco_seleccionado"]:"") . "",false,2);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"depositar_716");
}
}
?>form elemnts:
<label for="Tipo_de_operacion">Already made deposit:
<input type="checkbox" name="Tipo_de_operacion" id="Tipo_de_operacion" value="1" />
</label>

<label for="Banco_seleccionado">Type your deposit number:
<input type="text" name="Banco_seleccionado" id="Banco_seleccionado" value="" size="32" /></label>And the show if

<?php
if (ValidatedField('depositar_716','depositar_716')) {
if ((strpos((",".ValidatedField("depositar_716","depositar_716").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?>
Requiered field
<?php //WAFV_Conditional depositar.php depositar_716(2:)
}
}
}



?>

this checkbox internally is called "Tipo_de_operacion" the label out side is diffrent i want the user that if he is going to pay with a bank deposit he has to fill in a textfield with the deposit number, if he doesnt select the check box it should continue to insert the form to save the order for later payment.

I had no luck with the above technic to tell on server side validation that only if the checkbox is selected, what am i doing wrong here cause if i select the checkbox and fill the text field it works but thats not the point or goal to make this work,

Can we get a better example on how is it done with server side includes?

Thanks
Sades

Ray Borduin
09-20-2010, 06:50 AM
change:

:""

to

:"1"

That is the value to validate when the checkbox is not checked, if you set it to a non-blank value it will pass validation when the checkbox is not checked automatically.

Sades
09-22-2010, 05:25 PM
thank you worked nice