The MU forums have moved to WordPress.org

Adding custom fields to wp-signup.php (16 posts)

  1. KKWangen
    Member
    Posted 17 years ago #

    I want to add some custom fields to wp-signup.php, like "I've read the terms of use", - if unchecked I want the user to get some error messages like "Please read our terms before signing up".

    I also would like to add a field where you add your birthyear as it's going to be for people over 13 only, so I was wondering how I can create some code that checks that the year born is earlier than 1994 and if someone let's say write 1996 they get an error message like "Sorry, you have to be older than 13 to signup"

    So, do anyone know how to do this?

  2. zappoman
    Member
    Posted 17 years ago #

    You can do this by adding the code to wp-signup.php.

    I've made changes to my signup page as well, but not of this particular nature.

    The logic to check that they user properly completed the form is relatively straightforward in the existing file, you can probably add your own fields and check them much the same way that user name is checked.

    Good Luck.

  3. zappoman
    Member
    Posted 17 years ago #

    Oh yeah, I haven't figured out how to do this without core changes... but if you figure out some way to accomplish it then let me know! :)

  4. KKWangen
    Member
    Posted 17 years ago #

    I've added the following to signup php

    
    <input id="tos" type="checkbox" name="tos" value="tos" />
    <label for="tos">I'm older than 13 and have read the <a href="http://mysite.tld/tos/">Terms of use</a></label>
    
    

    Right under the 'just a username' please code, around line 243.

    But I'm not sure how to code an error message if the box isn't checked.

    I saw there was a line saying $filtered_results = apply_filters (223) - is this something I can use to make it work?

  5. Ovidiu
    Member
    Posted 17 years ago #

    I have answered this severall times, try and search again or click on my profile and look through those posts...

  6. zappoman
    Member
    Posted 17 years ago #

    I have made a bunch of changes to my wp-signup.php, so this may be a little bit hard to follow. But the following idea comes from wpmu-captcha...

    Inside of function validate_user_signup() you can add code after...

    extract($result);

    ...and before...

    if ( $errors->get_error_code() ) {
    signup_user($user_name, $user_email, $errors);
    return;
    }

    That validates the form fields you want. So something like...


    // check that the user checked the TOS
    if ('tos' != $_POST['tos']) {
    $em = "You must agree to our terms of service.";
    $errors->add('tos', __($em));
    }

    Then you can access the "errors" when you render the page. The normal signup used a table and sets the class of of the <tr> to 'error'....

    So in your function show_user_form() you put some code like this, above where you added your input...


    //verify the user agreed to terms of service
    if ( $errors->get_error_message('tos') ) {
    print '<tr class="error">';
    } else {
    print '<tr>';
    }

    Or something like that. ;)

    Hope that helps.

  7. zappoman
    Member
    Posted 17 years ago #

    Ovidiu's client side approach can be found here...

    http://mu.wordpress.org/forums/topic.php?id=3569&replies=5

    I like both approaches... I guess if you wanted to add more sophisticated signup items (like the captcha) then you may need the server side solution that I documented.

    Good luck.

  8. KKWangen
    Member
    Posted 17 years ago #

    Ovidiu: It was probably that I wanted to add several fields, not just the TOS that made use 'bad' search strings.

    Zappoman; thank you, it's much easier to figure this out when you know what codes to play with. I'm posting the code I ended up with incase there are others who want a stricly php soluton to a TOS checkbox:

    Add the following right after (About line 243)

    <label for="signupuser"><?php _e('Just a username, please.') ?></label>
    </p>
    <?php //verify terms
    	if ( $errors->get_error_message('tos') ) {
    		print '<p class="error">';
    	} else {
    		print '<p>';
    	} ?>
    		<input id="tos" type="checkbox" name="tos" value="tos" />
    		<label for="tos">I have read the <a href="http://yourdomain.tld/tos/">Terms of use</a></label>
    	<?php  //print error message
    		if ( $errmsg = $errors->get_error_message('tos') ) { ?>
    		<br /><strong><?php echo $errmsg ?></strong>
    	<?php } ?>
    </p>

    And then (just like zappoman said in his post) add the following code right after

    extract($result);
    (About line 260)

    // check that the user checked the TOS
    		if ('tos' != $_POST['tos']) {
    		$em = "You must agree to the terms of use.";
    		$errors->add('tos', __($em));
    	}

    This take care about the check for terms of service, but I'm still not sure how to create some function that check for age seperatly.

    Any search I made on that just lead me chaptcha solution and the mature blog plugin.

  9. zappoman
    Member
    Posted 17 years ago #

    For Age check I think I would do the same thing. Add an input textbox, and then in the validate user signup check that the $_POST[xxx] value matches your age requirement. Although I'd probably encapsulate the age checking code into a function of it's own just to keep the code a little cleaner.

    Cheers!

  10. drmike
    Member
    Posted 17 years ago #

    Do you want to be checking for age though? That gives you legal issueswith CAPPA here in the States.

  11. KKWangen
    Member
    Posted 17 years ago #

    If you mean COPPA; The magic age is 13, and everyone under 13 is children, and need their parents / legal guardians permission to sign up.

    So I want an agecheck to prevent children from automaticly signing up.

  12. lunabyte
    Member
    Posted 17 years ago #

    Age checks are useless. They know what it's for, and know what they have to put in. I skip it all together. It isn't worth the hassle.

  13. andrea_r
    Moderator
    Posted 17 years ago #

    Kids aren't stupid, folks. Most of them can at least add a few years to their age and lie about it if they want to.

  14. zappoman
    Member
    Posted 17 years ago #

    Maybe we should make a captcha that has a rolling regional trivia database that has pop culture reference to the era the person claims to be raised in. Like we could have "name that tune" for TV show theme songs? Or pop-culture catch phrases?

    What TV show did this catch phrase come from "I Love it when a plan comes together!"

    What product was sold with the slogan "Where's the beef?"

    ;)

  15. KKWangen
    Member
    Posted 17 years ago #

    Or: Does "Smells like teen spirit" mean something to you?

    There was actually a Norwegian cartoon on this with a while ago: A doorman asking everyone who wants to go into the night club if they ever danced to "Informer" with "Snow" together with if they really liked "Ice Ice Baby".. :D
    --------

    andrea; I do know they are smart, but I also have to believe there's at least 50% honest kids out there.

    And lunabyte: I'm a strong beliver in 'at least try'.

  16. mrjcleaver
    Member
    Posted 16 years ago #

About this Topic

  • Started 17 years ago by KKWangen
  • Latest reply from mrjcleaver