I would like to have a hidden registration field that is automatically updated with value retrieved from a cookie.
I tried doing this via dynamic reg fields as per https://www.youtube.com/watch?v=AyOS7C6wkhk. With the following code that updates value fvid with cookie fvid.
add_action (“ws_plugin__s2member_before_custom_field_gen”, “my_dynamic_field_options”);
function my_dynamic_field_options ($vars = array ()) {
$_field = &$vars["__refs"]["_field"];
if ($_field[“id”] === “fvid”) $_field[“options”] = end(explode("|",$_COOKIE[‘fvid’]))."|".end(explode("|",$_COOKIE[‘fvid’]))."|default"."\n" ;
}
The value does not get submitted even though I can see the fvid value in the registration form before I click submit (if i make it visible). Any suggestions on why the accurate cookie value is inserted in the form (when visible) but not submited with the form? or alternative way of doing it would be appreciated.
Inserting cookie value to hidden registration custom registration field
I am not going to watch the video, but I can’t see how anything added via add_action
is going to do what you want. Surely it would need to be add_filter
?
But, actually, you’d be much better off just building a custom registration form. There are several threads on here telling you how to do that, as well as a KB article.
No need to watch the video, it is just a source of the script from official S2member youtube channel. Add_action is used in the video. I will try the add_filter. Was hoping that there would be a simple hack to fill the hidden field on the backend rather than creating a custom form. Thanks for the suggestion.
Please note that add_filter
can’t just be swapped in for add_action
. You need a different hook. My point was that they do different things, and I doubt that something relying on an add_action
hook will get you what you want.
Fair enough. I was hoping I would be able to hack the code which I took from the S2member video for building dynamic registration fields but it did not work for my purpose. At this point I think the only solution is to build the form from scratch, unless someone has a workaround they used for a scenario similar to mine.