This topic is locked

Combining 3 text fields into one new field.

11/23/2006 7:31:49 AM
PHPRunner General questions
G
gdude66 author

Hi, I have a project with 3 text fields each 100 characters long. I would like to combine them on submit into a new field all together with no spaces. Eg tf1, tf2, tf3 into tfall. Is there an easy way to do this?

J
Jane 11/23/2006

Graeme,
you can do it using events.

Here is a sample code for the Before record added event:

function BeforeAdd(&$values)

{

$values["tfall"] = $values["tf1"].$values["tf2"].$values["tf3"];

return true;

}

G
gdude66 author 11/23/2006

Graeme,

you can do it using events.

Here is a sample code for the Before record added event:



Thanks for that Jane.

How do I then get it to leave a space between tf1 and tf2 and also tf2 and tf3?

D
Dale 11/23/2006

Im always a bit leary in giving a quick reply, hopefully I'm right with this one. Im no expert but give this a try.
function BeforeAdd(&$values)

{

$values["tfall"] = $values["tf1"]."" "".$values["tf2"]."" "".$values["tf3"];

return true;

}
Hopefully that will add the spaces in between. One side effect here. If $values["tf2"] is empty you may end up with 2 spaces in between the other fields.

G
gdude66 author 11/24/2006

Im always a bit leary in giving a quick reply, hopefully I'm right with this one. Im no expert but give this a try.

function BeforeAdd(&$values)

{

$values["tfall"] = $values["tf1"]."" "".$values["tf2"]."" "".$values["tf3"];

return true;

}
Hopefully that will add the spaces in between. One side effect here. If $values["tf2"] is empty you may end up with 2 spaces in between the other fields.



Thanks for that I realised that half an hour after posting.