Change Casing before updating db

Change Casing before updating db

mankramomankramo Posts: 24Questions: 5Answers: 0

Hello Everyone, please how do i perform case changing on data submitted before calling ->process( $_POST ). That is to say i want to change all to ucwords() before i insert. Currently this is what am doing :

->fields( ... )
->validator( function ( $editor, $action, $data ) {
if ( $action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT ) {
foreach ( $data['data'] as $pkey => $values ) {
if ( $values === 'currency_name' ) {
$values['currency_name'] = ucwords(strtolower($values['currency_name']));
}
}
}
} )

```->process( $_POST )```
```->json();```

That is, i want to call ucwords() on on the data in currency_name . but its not working,

Please help me,

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,984Questions: 87Answers: 421
    Answer ✓

    you cannot change any values using a validator. You would need to use a set formatter.
    e.g.

    Field::inst( 'currency_name' )
       ->setFormatter( function($val, $data, $opts) {
              return ucwords(strtolower($val));
        }),
    
  • mankramomankramo Posts: 24Questions: 5Answers: 0

    Thank you very much @rf1234 B)

This discussion has been closed.