|
Diego Medeiros - 2012-12-04 16:14:34
Hi Mr. Sosins,
I'm a huge fan of yor work, specially the AUTOFORM class!
By the way, I'm trying to reach something without success and I've spent a good time on it and I would be very very grateful if you show me any direction on this. (and if this little help of you don't represent any bother for you, obviously).
And the question is:
"When I use INSERT_FORM and delete a kind of field like REQUIRED by the $EXCLUDE (with the objective of inserting a CUSTOM_HTML of this field later), what can i do on the class so it could understand that this field is a REQUIRED, even if it's in CUSTOM_HTML?
Thank you very much,
Diego
Arturs Sosins - 2012-12-04 19:58:37 - In reply to message 1 from Diego Medeiros
Hello,
thats awesome. ;)
Well as I remember there was an option to said custom validation callbacks.
Sou you could define custom callback for each custom element as this:
function custom1_required($arr){
if(trim($arr["custom1"]) != ""){
return true;
}
else{
return false;
}
}
And then add it to the form object:
$form->add_custom_validation("custom1_required", "This element needs to be filled");
Or if all the custom elements can use same error message, you can check them all inside one custom validation callback.
Tell me if that does not make sense, and I'll try to provide more thorough example ;)
Diego Medeiros - 2012-12-04 21:42:35 - In reply to message 2 from Arturs Sosins
Hi Mr. Sosins,
thanks for your attention!
I'm afraid I have not made myself clear before. I'm trying to change the class in a way it is done automatically.
I've already figured it out that the validation it's done by:
if ($this->required($data["validate"])){
but I don't know exactly in which method of the class I should repeat it, knowing that this field has been excluded by $exclude
and so isn't on $table_info...
Arturs Sosins - 2012-12-04 23:13:31 - In reply to message 3 from Diego Medeiros
Ok I think I got it.
Well actually $table_info returns all fields of table, then inside private function validate($table_info, $exclude, $count) function it checks which fields where excluded.
So you could for example create a private method, which checks if there a custom input with specified name like this:
private check_custom_input($count, $name){
foreach($this->user_html[$count] as $key => $user_html)
{
if($user_html["name"] == $name)
{
return true;
}
}
return false;
}
And then call is inside validate method like this:
if(!in_array($field["name"], $exclude) || $this->check_custom_input($count, $field["name"]))
I have not tested it, but I think that in this case you can exclude some input elements and then provide the input element as custom HTML with the same name, then all the validation that was meant for that element should still be applied to custom one.
So you can try it and tell me if there is anything else I can help with ;)
Diego Medeiros - 2012-12-05 16:31:57 - In reply to message 4 from Arturs Sosins
Thank You Mr. Sosins!! Thanks for your help I just implanted the solution I was looking for!!
So, if anybody else needs it, I'll show right down what I've done:
1. I've added your function CHECK_CUSTOM_INPUT to the class.
2. I've added an ELSE to the condition "if(!in_array($field["name"], $exclude) )" from the VALIDATE function with the following content:
if($this->check_custom_input($count, $field["name"])){
if($field["validate"] )
{
//$_POST custom não possuem $count
if(!$this->char_validate($field, $count, $_POST[$field["name"]], $valid)){
$valid = false;
}
}
}
3. Done ;)
Arturs Sosins - 2012-12-05 17:20:38 - In reply to message 5 from Diego Medeiros
Awesome. Thanks for sharing ;)
|