Viewing 1 replies (of 1 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    Here’s an example of how you can use wpmem_register_form_rows filter to add a pre-populated value.

    add_filter( 'wpmem_register_form_rows', function( $rows, $tag ) {
        // If this is a registration, $tag will be "new"
        if ( 'new' == $tag ) {
    
            $input_meta = 'user_email';
    
            // Check for a query string value.
            $query_var = wpmem_get( $input_meta, false, 'get' );
            // If there's a value, do a str_replace of the input tag's value=""
            if ( $query_var ) {
                $get_val = $query_var; // gets the query string val and escapes it.
                $old = 'value=""'; // looks for empty value="" in the <input> tag
                $new = 'value="' . esc_attr( $get_val ) . '"'; // new value, making sure to escape the result
                // do the str_replace() on this fild in the rows array.
                $rows['user_email']['field'] = str_replace( $old, $new, $rows[ $input_meta ]['field'] );
            }
    
        }
        return $rows;
    }, 10, 2);

    This example uses PHP’s str_replace() (and some “setup” in order to do that) to insert the value into the HTML <input> tag’s “value” attribute, doing it as a search/replace. I thought there was probably an easier approach, but the alternative is to rerun the function that creates the input tag (not difficult, but not what I wanted, either). So that leads to the conclusion that there needs to be some possibility of having a prepopulated value in the plugin’s fields array (what’s used to build the form) added by filter hook directly. Since I’m working on 3.5.0 for a major release coming shortly, that’s been added to the list of items for that version.

Viewing 1 replies (of 1 total)
  • The topic ‘Fill Register form field using URL GET Method’ is closed to new replies.