• I am using wp-members 2.8.1 with wp 3.5.
    I want to customize the form buttons and last required label.
    I tried with sample code and suggestion by you for custom filter, posted here http://ww.wp.xz.cn/support/topic/plugin-wp-members-customize-submit-button, it worked for changing button text.

    But to customize the html to a larger extent, its not working.
    I have used following code:

    add_filter( 'wpmem_register_form', 'my_submit_button_filter' );
    function my_submit_button_filter( $string ) {
     $needle = '<div class="button_div">
    		<input name="reset" value="Clear Form" class="buttons" type="reset">
    		<input name="submit" value="Submit" class="buttons" type="submit">
    	    </div>
    	    <font class="req">*</font>Required field';
    
      $replacement = '<div class="button_div">
    		     <input type="reset" class="btn" value="Clear Form" name="reset" style="float:right;">
    		     <input type="submit" class="btn btn-primary" value="Register" name="submit" style="float:left;">
    		     <div style="clear:both"></div>
    		   </div>
    		   <div class="reqnote"><span class="req">*</span>Required field</div>';		
    
    	$string = str_replace( $needle, $replacement, $string );
    	return $string;
    }

    But its not working!! The html for needle I directly copied from firebug and also from view-page-source, so it should match and replace as required.

    Could you please let me know what I am doing wrong? I need it to make button aligned horizontally below form and ‘required’ label to make more space. Please help.

    http://ww.wp.xz.cn/extend/plugins/wp-members/

Viewing 7 replies - 1 through 7 (of 7 total)
  • If what you want to do is changing the styling of the form, why don’t you just edit the wp-members.css file and customize according to your needs? Of course you should copy it to your theme’s directory to preserve your modifications. This worked for me.

    Thread Starter Shashank Shekhar

    (@shashankitsoft)

    Customizing css is not just the only criteria, as you can see I have changed the html also. class=”btn btn-primary” are twitter bootstrap classes, do u think its okay to write those lengthy classes again in my custom css for wp-members buttons, if I already have bootstrap css included in my theme. Also, if I write them the original wp-members css is conflicting it.
    Further, css support the associated html. A element can be styled when it has proper html what needed. For example, in original ‘<font class=”req”>*</font>Required’ html has no div around so I can’t give padding/margin to this, the font tag cannot be used as its obsolete in w3c validation.
    Also, I can’t apply float:left, right and additonal <div style=”clear:both”></div> with css. The whole form get disturbed if I really do, as it have no unique id or class on them (2 buttons).

    Lastly, this was just an example what I posted above, may be I need to customize more html…. then? The main issue is why wp-members custom filter working for btton string but not working for custom html override as it was documented.

    Well, the code you are currently using was intended to change a string and that is the button text, note that you’re using the $string variable. To filter the form content, you must use the $form variable.

    From this filter’s docs:

    “The registration form is brought in with $form
    You can append to it or filter it”

    Thread Starter Shashank Shekhar

    (@shashankitsoft)

    Well, it looks good at first, and thanks for the help. But I even tried with it, to change the variable from $string to $form, it not worked.
    However when I thoroughly checked it was really foolish to change the variable, variable argument is just an variable, I can use $form, $string, $xyz, whatever… will ofcourse not work.
    If the filter is same i.e., ‘wpmem_register_form’ changing of a variable will not make it work.
    Even you can check by print_r($form); or print_r($string); or even print_r($xyz); inside the custom filter function, all will give the full form html.

    ‘wpmem_register_form’ is made for full form html, and that I am using already, what we change in it depend on us.
    Hope we get real answer soon. πŸ™‚

    Looking back at my answer I now realize how foolish it was. I have no idea what I was thinking :/

    Plugin Author Chad Butler

    (@cbutlerjr)

    Sometimes it can be difficult to track down a specific string within a string when you are filtering larger blocks of html. Rather than try to match the line breaks and tabs/indents, for filtering a larger string, I find it is often easier to remove the line breaks and such first.

    Using something like this as a pre-filter works well:

    str_replace( "\n", "", $string );

    Or a little more fancy for newlines, tabs, and extra spaces:

    /**
     * replace new line, tab, and double space
     * with no space, single space, and single space
     */
    $old = array( "\n", "\t", "  " );
    $new = array( "", " ", " " );
    str_replace( $old, $new, $string );
    Thread Starter Shashank Shekhar

    (@shashankitsoft)

    Thanks Chad, for a nice effort and help. Yes I was also thinking its the matter of tabs, newline and spaces.
    But I tried to addup you str_replace before actual replacement, and then echoed and copied the new string via browser source. Made it as a source again to replace with the required final string I want. It not worked upto this with single replacement, but I made some more modifications for an hour and finally got what made it work !!!
    Here how I put it…
    ———

    add_filter( 'wpmem_register_form', 'my_submit_button_filter' );
    function my_submit_button_filter( $string ) {
    	// the html of the form is the parameter $string
    
    	// use str_replace like:
    	// $new_string = str_replace( $needle, $replacement, $haystack );
    
    	//$string  = str_replace( 'Submit', 'Register', $string );
    
    	/**
    	 * replace new line, tab, and double space
    	 * with no space, single space, and single space
    	 */
    	$old = array( "\n", "\t", "  " );
    	$new = array( "", " ", " " );
    	$string = str_replace( $old, $new, $string );
    	$string = str_replace( $old, $new, $string );	// Intentionally done two times, as continuous tabs and double space converted to single space will cause a double space, which removed through it.
    	//echo $string;									// Echo and copy needle html from browser source to paste below
    	/* Below needle string is exact copy of browser source, don't edit it otherwise no match and not work */
    	$needle = '<div class="button_div">
     <input name="reset" type="reset" value="Clear Form" class="buttons" />
     <input name="submit" type="submit" value="Submit" class="buttons" />
     </div><font class="req">*</font>Required field';
     $needle = str_replace( $old, $new, $needle );		// needle is also processed for new line, tab, and double space
    
    	$replacement = 	'<div class="button_div">
    						<input type="reset" class="btn" value="Clear Form" name="reset" style="float:right;">
    						<input type="submit" class="btn btn-primary" value="Register" name="submit" style="float:left;">
    						<div style="clear:both"></div>
    					</div>
    					<div class="reqnote"><font class="req">*</font>Required field</div>';		
    
    	$string = str_replace( $needle, $replacement, $string );
    
    	return $string;
    
    }

    ————
    I found this trick as an excellent solution to do such string replacements in different places.
    I hope other user will find it great wandering for the solution but scratching their heads.. πŸ™‚
    I wish you please try it at your end (may be you write shorter code without multiple replacements), and also put in this your wp-member filter documentation so other users may get help!!

    Thanks Chad!
    Shashank

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Customize register form buttons html, filter not working’ is closed to new replies.