WordPress.org

Ready to get started?Download WordPress

Forums

WP-Members
[resolved] Radiobox Register Form (6 posts)

  1. jrtideias
    Member
    Posted 9 months ago #

    Hi everbody,
    I'd like add a radio buttons. Is it possible using wpmem_register_form filter hook? Or anybody know how can I add it?

    thanks

    http://wordpress.org/extend/plugins/wp-members/

  2. Chad Butler
    Member
    Plugin Author

    Posted 9 months ago #

    Radio buttons are not natively supported yet, but may be in the future.

    Yes, you could add them with the wpmem_register_form filter. I would create a placeholder field (text) in the field manager and then use PHP's str_replace to replace the text field with the radio button.

  3. jrtideias
    Member
    Posted 9 months ago #

    Ok.
    Thanks!

  4. jrtideias
    Member
    Posted 9 months ago #

    Hey,
    sorry I'm not a programmer, so I tried this:

    add_filter( 'wpmem_register_form', 'input_replace' );
    function input_replace( $form )
    {
    
    	$old = array(  'test','text', '' );
    	$new = array(  'test','radio', 'sim' );
    
    	$form = str_replace( $old, $new, $form );
    
    	return $form;
    }
    
    and this:
    add_filter( 'wpmem_register_form', 'input_replace' );
    function input_replace{
    	$old = '<input type="text" class="textbox" value="" id="test" name="test">';
    	$new = '<<input type="radio" name="test" value="yes">yes<input type="radio" name="test" value="no">no';
    
    	$form = str_replace( $old, $new, $form );
    
    	return $form;
    }

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    but doesn't work...

    Can you help me, please?

  5. Chad Butler
    Member
    Plugin Author

    Posted 9 months ago #

    I'm not sure what you are doing with the first one, but the second has a couple of problems.

    First, you neglected to include a section for arguments when you defined your function:

    function input_replace{

    This will create a syntax error as your function must have () after the function name. And in this case, you need to pass the generated form to the function as an argument:

    function input_replace( $form ) {

    Second, the string that you are searching for (defined as $old in your code) MUST be an EXACT match of what is generated in the form. I would suggest the following:

    • I assume that you have created this field as a placeholder in the plugin's field manager. If not, you need to do that.
    • Bring up the form in your browser and view source in your browser.
    • Find the field in the html source and copy/paste that into your code as the string you are searching for.

    My guess is the string you should be searching for in this should look something like this (assuming you called it "test" and it is a text field):

    <input name="test" type="text" id="test" value="" class="textbox" />

  6. Creative Paul
    Member
    Posted 2 months ago #

    Great Man !

Reply

You must log in to post.

About this Plugin

About this Topic