Results 1 to 2 of 2

Thread: Custom fields on registration form - functions.php FAIL

  1. #1
    Thread Starter
    Junior Member lcooper1784's Avatar
    Join Date
    Apr 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Custom fields on registration form - functions.php FAIL

    So I've followed the instructions here: http://docs.appthemes.com/tutorials/...stration-form/, and added the requisite code to my shiny, untouched functions.php file (copied to my child theme folder), but it does not work for me. My whole site went kaboom. Has anyone had success getting the code provided by that tutorial to work with CP?

    Here's a link to my site: http://www.kingwoodpets.org


    and here's the content of my functions.php file (previously, I'm about to delete the new code so I can work on other things):
    PHP Code:
    <?php
    /**
     * Theme functions file
     *
     * Child theme Funtions.php
     *
     * @package ClassiPress
     * @author AppThemes
     */

    // current  version
    $app_theme 'ClassiPress';
    $app_abbr 'cp';
    $app_version '3.1.9';
    $app_edition 'Ultimate Edition';
    $app_stats 'today';

    // define rss feed urls
    $app_rss_feed 'http://feeds2.feedburner.com/appthemes';
    $app_twitter_rss_feed 'http://twitter.com/statuses/user_timeline/appthemes.rss';
    $app_forum_rss_feed 'http://www.appthemes.com/forum/external.php?type=RSS2';

    // define the transients we use
    $app_transients = array($app_abbr.'_cat_menu');

    // Framework
    require( dirname(__FILE__) . '/framework/load.php' );

    scb_register_table'app_pop_daily'$app_abbr '_ad_pop_daily' );
    scb_register_table'app_pop_total'$app_abbr '_ad_pop_total' );

    require( 
    dirname(__FILE__) . '/framework/includes/stats.php' );

    // Theme-specific files
    require( dirname(__FILE__) . '/includes/theme-functions.php' );

    // display the custom fields
    function at_custom_fields() {
    ?>
      <fieldset class="at_fieldset">
       <legend><?php _e('Personal Information (required)''appthemes'); ?></legend>
       <p>
         <label for="at_name"><?php _e('Name''appthemes'); ?></label><br/>
         <input class="text" type="text" name="at_name" id="at_name" value=<?php if (isset($_POST['at_name'])) echo esc_attr($_POST['at_name']); ?>>        
       </p>
       <p>
         <input type="checkbox" name="at_age" id="at_age" value="yes" <?php echo checked( ! empty( $_POST['at_age'] ) )?> /> 
         <label for="age"><?php _e('I\'m over 18 ''appthemes'); ?></label>        
      </p>        
      </fieldset>
      <br/>
      <fieldset class="at_fieldset">
       <legend><?php _e('Additional Information''appthemes'); ?></legend>        
       <p>
         <label for="at_referral"><?php _e'How did you find us?''appthemes' ); ?></label><br/>
         <select name="at_referral" id="at_referral">
           <option value=""></option>
           <option value="Friend" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Friend' == $_POST['at_referral'] ); ?> ><?php _e('Friend''appthemes'); ?></option>
           <option value="Search Engine" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Search Engine' == $_POST['at_referral'] ); ?> ><?php _e('Search Engine''appthemes'); ?></option>
           <option value="Advertising" <?php echo selected ( isset( $_POST['at_referral'] ) && 'Advertising' == $_POST['at_referral'] ); ?> ><?php _e('Avertising''appthemes'); ?></option>
         </select>
       </p>
       <p>
         <label for="at_referral_id"><?php _e('Referral ID''appthemes'); ?></label><br/>
         <input type="text" class="text" class="at_number" name="at_referral_id" id="at_referral_id" value=<?php if (isset($_POST['at_referral_id'])) echo esc_attr($_POST['at_referral_id']); ?>>
         <p class="at_referral_note"><?php _e('If you have a Referral ID please insert in the field above. It will give you access to special discounts to you and the referral.''appthemes'); ?></p>
        </p>
        </fieldset>    
        <style type="text/css">
        .at_fieldset { border: 1px solid #ccc; padding: 10px; border-radius: 5px; }
        .at_referral_note { font-size: 12px; color: #ccc; }
        .at_number { width: 100px }
        </style>
    <?php
    }

    // display the custom fields on registration form
    add_action'register_form''at_custom_fields' );

    // validate fields
    function at_validate_custom_fields$login$email$errors ) {
     
      
    // fields to be validated
      
    $fields = array(
        
    'at_name' => __'Name''appthemes' ), 
        
    'at_age' => __'Age''appthemes' ),
      );
     
      
    // check for empty required fields an display notice
      
    foreach ( $fields as $field => $value ) {
        if ( empty( 
    $_POST[$field] ) ) {
            
    $errors->add('empty_fields'__('<strong>ERROR</strong>: &ldquo;''appthemes').$value.__('&rdquo; is a required field.''appthemes'));
        }
      }
     
      
    // check for invalid names (letters and spaces)
      
    if ( ! empty( $_POST['at_name'] ) && preg_match("/[^a-zA-Z ]/"$_POST['at_name']) ) {
        
    $errors->add('invalid_name'__('<strong>ERROR</strong>: &ldquo;''appthemes').$fields['at_name'].__('&rdquo; does not contain a valid name.''appthemes'));
      }
     
      
    // additional custom fields validations here
     
    }

    // validate custom fields
    add_action'register_post''at_validate_custom_fields'10);

    // register the extra fields as user metadata
    function at_register_custom_fields$user_id$password ""$meta = array() )  {
     
        
    // custom fields
        
    $fields = array(
            
    'at_name',
            
    'at_age',
            
    'at_referral',
            
    'at_referral_id',
        );
            
    // cleans and updates the custom fields
        
    foreach ( $fields as $field ) {
            
    $value stripslashestrim$_POST[$field] ) ) ;
            if ( ! empty( 
    $value ) ) {
               
    update_user_meta$user_id$field$value );
            }
        }
     
    }
    // save the custom fields to the database as soon as the user is registered on the database
    add_action'user_register''at_register_custom_fields' );

    // display custom fields/values on the backend or frontend
    function at_custom_fields_display$user ) {
       
    $user_id $user->ID;
    ?>
       <?php if ( is_admin() ) { ?>
            <!-- // show the backend HTML -->
        <h3><?php _e('Additional Information''appthemes'); ?></h3>
     
         <table class="form-table">
        <tr>
          <th><label for="at_name"><?php _e('Name''appthemes'); ?></label></th>
          <td>
           <input class="text" type="text" name="at_name" id="at_name" value="<?php echo get_user_meta$user_id'at_name'true ) ; ?>">        
           </td>
        </tr>
        <tr>
          <th><label for="at_referral"><?php _e'How did you find us?''appthemes' ); ?></label></th>
          <td>
           <strong><?php echo get_user_meta$user_id'at_referral'true ) ; ?></span>
          </td>
        </tr>        
        <tr>
          <th><label for="at_referral_id"><?php _e('Referral ID''appthemes'); ?></label></th>
           <td>
             <strong><?php echo get_user_meta$user_id'at_referral_id'true ) ; ?></strong>
           </td>
          </tr>
          </table>
     
        <?php } else { ?>
     
            <!-- // show the frontend HTML -->
        <fieldset>
           <legend><?php _e('Personal Information''appthemes'); ?></legend>
           <p>
            <label for="at_name"><?php _e('Name''appthemes'); ?></label>
            <input class="text" type="text" name="at_name" id="at_name" value="<?php echo get_user_meta$user_id'at_name'true ) ; ?>">        
           </p>
        </fieldset>
        <br/>
        <fieldset>
           <legend><?php _e('Additional Information''appthemes'); ?></legend>        
           <p>
              <label for="at_referral"><?php _e'How did you find us?''appthemes' ); ?></label>            
              <strong><?php echo get_user_meta$user_id'at_referral'true ) ; ?></strong>
            </p>
            <p>
              <label for="at_referral_id"><?php _e('Referral ID''appthemes'); ?></label>
              <strong><?php echo get_user_meta$user_id'at_referral_id'true ) ; ?></strong>
             </p>
           </fieldset>
     
        <?php ?>
    <?php
    }

    // display the custom fields on the user profile page (frontend and admin)
    add_action'show_user_profile''at_custom_fields_display' ); // frontend
    add_action'edit_user_profile''at_custom_fields_display' ); // backend

    // updates custom fields
    function at_custom_fields_update$user_id ) {
     
        if ( !
    current_user_can'edit_user'$user_id ) )
            return 
    false;
     
        
    // updatable fields
        
    $fields = array(
            
    'at_name',
        );
     
        foreach ( 
    $fields as $field ) {
            
    $value stripslashestrim$_POST[$field] ) ) ;
            if ( ! empty( 
    $value ) ) {
                
    update_user_meta$user_id$field$value );
            }
        }
     
    }
    // additional fields update
    add_action'edit_user_profile_update''at_custom_fields_update' );
    add_action'personal_options_update''at_custom_fields_update' );
    Is there just some stupid simple step I'm missing? (that was perhaps not explained in the tutorial?)

  2. #2
    Veteran ajamm's Avatar
    Join Date
    Nov 2011
    Location
    New Zealand
    Posts
    309
    Thanks
    26
    Thanked 32 Times in 29 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding New Fields To Registration Form
    By ozzy00200 in forum Report JobRoller Bugs
    Replies: 22
    Last Post: October 27th, 2014, 01:47 PM
  2. Adding custom fields to registration form
    By tina020 in forum ClassiPress General Discussion
    Replies: 4
    Last Post: July 15th, 2012, 11:35 PM
  3. [MOD NEEDED] How to add Name and Surname fields to registration form?
    By project21 in forum JobRoller General Discussion
    Replies: 3
    Last Post: November 24th, 2011, 02:47 AM
  4. UK Counties, Postcode Areas and Regions. Create Custom Fields for registration form
    By m4rty5miff in forum ClassiPress General Discussion
    Replies: 3
    Last Post: August 16th, 2010, 09:32 AM