FormIt Custom Hook to delete names from a textfield

Hi,

I got a form with (e.g.) 3 Fields:
name, surname and text.

What I want ist that the text is checked if it contains the name or surname. And if is, the names should be removed and then send it.

I wrote a custom hook:

<?php
// read values:
$name = $hook->getValue('name');
$surname = $hook->getValue('surname');
$text = $hook->getValue('text');

// Delete Names:
$text = $text
$search1 = $name;
$trimmed1 = str_replace($search1, '', $text);

$text2 = $trimmed1;
$search2 = $surname;
$trimmed2 = str_replace($search2, '', $tex2);

$hook->setValue('text', $trimmed2);
return true;

But the text is now complete blank. Did someone have an idea?

OK, I got.

<?php

$name = $hook->getValue('name');
$surnname = $hook->getValue('surname');
$text = $hook->getValue('text');




$search1 = $name;
$trim1 = str_ireplace($search1, " ", $text);

$search2 = $surname;
$trim2 = str_ireplace($search2, " ", $trim1);

$hook->setValue('text', $trim2);
return true;
1 Like

Don’t forget to use the trim function to remove unwanted spaces after you remove the “names” from the field.

1 Like

That sound good. Thanks for that hint.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.