I wish to pass an array of arbitrary content via a hidden field in a form which uses the POST method

$targets = any old array;
...
build form to include ...
<input type=hidden id=targets title=targets name=_targets value=\"".htmlspecialchars( serialize( $targets ))."\">

Clearly this requires some use of the htmlspecialchars() or related wrapper functions but I am darned if I can figure out a combination which is guaranteed to work for an array of arbitrary content.

Any help appreciated & I can readily figure out how to unserialize($_POST) from your reply

Member Avatar for diafol

Do you really need to clean it? Clean it after it's been posted. Perhaps I'm missing the point.

If I simply put value=serialize( $targets ) my form does not display properly though.

I need $targets to be made available to the routine handling the POSTed data.

Got it :)

base64_encode( serialize( ))
...
unserialize( base64_decode( ))

Thank you for reading.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.