Welcome Guest, Not a member yet? Register   Sign In
Just three little questions?
#1

[eluser]danfloun[/eluser]
Hi,
How can I use validation on a textarea that doesn't accept a value="" parameter?

Secondly, how can I format the contents of a form field before it is passed to the database. I need uk 11 digit telephone numbers to be formatted like:

Code:
##### ######

The first part being the area code but I don't what brackets round it.
Is it a case of Regex expressions or what?

and third,
Is it possible to use form field validation that requires at least one of two fields to have data entered!

For example,

Field One
Field Two

On validation it checks to see if either field has data. If either or both fields contain data it verifies. If neither field contains data it fails.

Possible?

Thanks

Danny
#2

[eluser]BravoAlpha[/eluser]
[quote author="danfloun" date="1187053228"]How can I use validation on a textarea that doesn't accept a value="" parameter?[/quote]
Code:
<textarea name="whatever"><?php echo $this->validation->whatever; ?></textarea>
#3

[eluser]Derek Allard[/eluser]
And to finish off the three questions

[quote author="danfloun" date="1187053228"]
Secondly, how can I format the contents of a form field before it is passed to the database. I need uk 11 digit telephone numbers to be formatted like:

Code:
##### ######
[/quote]
Yup, either regex, or liberal use of substr. The substring is probably easier if you aren't familiar with regex.

Quote:and third,
Is it possible to use form field validation that requires at least one of two fields to have data entered!
I've never tested this, but in the validation rules you have "matches[field]", so I see no reason you couldn't use matches and required together.

Let us know if that works for you.
#4

[eluser]Michael Wales[/eluser]
For question three: use a callback function. If you use required it will require both of those fields to be filled and matches isn't what you are looking for (I assume you potentially want different inputs in both).

Code:
$rules['field1'] = 'callback__check_field';

function _check_field($field1) {
  $field2 = $this->validation->field2;
  if (($field1 !== FALSE) || ($field2 !== FALSE)) {
    return TRUE;
  } else {
    $this->validation->set_message('_check_field', 'Either field1 or field2 must have a value.');
    return FALSE;
}

You should only have to call that function from either field1 or field2 - as callback functions should be called to verify the data input into the field (even if there was no data entered).
#5

[eluser]danfloun[/eluser]
walesmd,

Indeed you are correct, match will not work for what I want.
However your solution did!

Many Thanks

and for the other help also, I have nearly got it all done.

Danny
#6

[eluser]Derek Allard[/eluser]
Glad you've got it working Danny. After having Michael re-phrase your question, I can see now that you don't want both fields the same, so yeah, my solution wouldn't work. Thanks Michael for dropping in!




Theme © iAndrew 2016 - Forum software by © MyBB