Biscuit128
Biscuit128

Reputation: 5408

Pass PHP object as html radio button value

If i have a custom object, and I want to pass it as the form value in a radio button selection - then I have to do the following;

<input type="radio" name="appNames" value="<?php echo $app ?>"> <?php echo $name ?><br>

Now - this seems to just invoke toString() on my object meaning that when I pick it up later down the line, it is just a String.

Passing the following also does not work - my question therfore is - how can i pass this information to the next page?

<input type="radio" name="appNames" value="<?php $app ?>"> <?php echo $name ?><br>

Would adding it to a session be the correct approach?

Thanks

Upvotes: 0

Views: 223

Answers (1)

deceze
deceze

Reputation: 522451

You can only "pass" through an HTML form whatever you can store in HTML attributes, which is text. You could serialize the whole object to store it in an attribute, but that's quite a weird approach.

You should be storing some identifying value in the HTML attribute that allows you to reconstruct the object later. Typically you store an id or something similar, and then have a lookup table/array what kind of object belongs to which id. If you need to store more state than that, then yes, you should probably store that in the session.

Upvotes: 1

Related Questions