Adding Fields

Discussion in 'Customization & add-ons' started by jschemmel, Sep 26, 2006.

  1. jschemmel

    jschemmel New Member

    Joined:
    Sep 16, 2006
    Messages:
    15
    I want to add a requied field on the signup page where the name of the company someone works for must be entered. I'd like this field to be part of the Address Info group. I've added the field but it is displayed above the address area.

    How do you control the location of added fields? I have looked over the code but seem to be missing the part related to added fields.

    Thanks in advance for the help!

    JJ
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Instructions for the text field:

    at aMember Cp -> Add Fields, set field to be NOT added to signup page.

    Then edit amember/templates/signup.html
    add where you want the field to appear:
    PHP:
    <tr>
        <
    th><b>My Field</b><br />
        <
    div class="small">my field description</div></th>
        <
    td><input type="text" name="fieldname" value="{$smarty.request.fieldname|escape}size="30" />
        </
    td>
    </
    tr>
  3. jschemmel

    jschemmel New Member

    Joined:
    Sep 16, 2006
    Messages:
    15
    Alex,

    Thanks! I'll give this a try and post a note on the outcome.

    JJ
  4. jschemmel

    jschemmel New Member

    Joined:
    Sep 16, 2006
    Messages:
    15
    Alex,

    Your code works jsuts as I hoped.

    Here is a followup question. How do I pass the value for this field to the profile page. If I try to edit my profile the field that I added on the signup page shows up blank on the profile page. If I save changes the value for this field becomes null.

    Thanks for the help.
  5. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Please contact us via helpdesk - something is wrong.
  6. jschemmel

    jschemmel New Member

    Joined:
    Sep 16, 2006
    Messages:
    15
    I have sent a message to the help desk.
  7. xe912

    xe912 New Member

    Joined:
    Feb 13, 2006
    Messages:
    15
    could you post a solution to this problem?
  8. jschemmel

    jschemmel New Member

    Joined:
    Sep 16, 2006
    Messages:
    15
    Here is the code Alex provided (with the specifics for my page removed and TEXT and fieldname inserted in its place)

    <tr>
    <th>#_TPL_TEXT#</th>
    <td><input type="text" name="fieldname" value="{$user.data.fieldname|escape}" size="30" />
    </td>
    </tr>
  9. bclark

    bclark New Member

    Joined:
    Jul 1, 2007
    Messages:
    1
    Sorry, I am new and went through the instructions and cannot find:

    aMember Cp -> Add Fields

    I need to add some user fields to sign up page...actually quite few fields from a table.
  10. smessina

    smessina New Member

    Joined:
    Jun 3, 2008
    Messages:
    7
    Can you use the same fieldname placeholder (ie. {$user.data.fieldname|escape} ) to insert the information into a system e-mail?
  11. ywirasin

    ywirasin New Member

    Joined:
    Sep 8, 2008
    Messages:
    2
    Custom field not resolving

    After doing this on my profile.html file, the field appears however the $user.data.fieldname|escape is not resolving. As such, when it comes to the browser, the value is blank and does not capture any data. However, if I turn the field's "Display and allow editing" for profile page on the Admin's Add Field page, I obviously get two of the same inputs, but now the $user.data.fieldname|escape tag resolves correctly. I've put in a support request, however, has anyone else run into this and solved it?

    cheers,
    -m
  12. ywirasin

    ywirasin New Member

    Joined:
    Sep 8, 2008
    Messages:
    2
    Ok - Big thanks to the support team for helping us with this! Since there might be others facing the same issue, here's what they developed, broken down into steps for you to get your profile page working. This might be fixed in a future version, but as of September 12, 2008, this is the solution, summarized:

    Step 0: Backup your profile.html and profile.php files.

    Step 1: Put your field where you want you want in profile.html

    If your "added field" is a common field use this:
    PHP:
       <input type="text" name="fieldname" value="{$user.data.fieldname|escape}size="30" />
    If your "added field" is a SQL field use this:
    PHP:
       <input type="text" name="fieldname" value="{$user.fieldname|escape}size="30" />
    Step 2: Set the added custom field to "Don't display"

    Step 3: In profile.php, replace your "save_profile" function with this to enable saving of your custom fields:

    PHP:
    function save_profile(&$vars, &$user){
        global 
    $db$config;
        global 
    $_amember_id$member_additional_fields;

        
    $fields_to_change = (array)$config['profile_fields'];

        
    $custom_fields = array('ADD','YOUR','CUSTOM','FIELDS','HERE','LIKE','THIS');

        
    $maf = array();
        foreach (
    $member_additional_fields as $f){
            
    $maf[$f['name']] = $f;
            
    // Set empty values for all fields that were not submited.
            // Need to do this to get validation functions working for radio buttons.
            
    if(!$vars[$f[name]]) $vars[$f[name]] = '';
        }

        
    $error = array();
        foreach (
    $vars as $k=>$v){
            
    $field $k;

            if (
    in_array($k$fields_to_change))
                
    $field_type 1;
            elseif (
    in_array($k$custom_fields) || $maf[$k]['display_profile'] || $maf[$k]['display_affiliate_profile'])
                
    $field_type 2;
            else {
                continue;
            }

            
    ///check username
            
    if (($k == 'login') && ($v != $_SESSION['_amember_login']) && $err=check_new_username($v)){
                
    $error[] = sprintf(_MEMBER_PROFILE_ERROR1$err);
                
    $user['login'] = $v;
                continue;
            }
            
    ////

            
    if (($k == 'email') && !check_email($v)){
                
    $error[] = _MEMBER_PROFILE_ERROR2;
                
    $user['email'] = $v;
                continue;
            } elseif ((
    $k == 'email') && $config['unique_email']){
                
    $ul $db->users_find_by_string($vars['email'], 'email'1);
                if(
    $ul && ($ul[0][member_id] != $_amember_id)){
                    
    $error[] = _MEMBER_PROFILE_ERROR3;
                    continue;
                }
            }

            if ((
    $k == 'name_f') && !strlen($v)){
                
    $error[] = _MEMBER_PROFILE_ERROR4;
                
    $user['name_f'] = $v;
                continue;
            }
            if ((
    $k == 'name_l') && !strlen($v)){
                
    $error[] = _MEMBER_PROFILE_ERROR5;
                
    $user['name_l'] = $v;
                continue;
            }
            
    /// check password
            
    if ($k == 'pass0'){
                if (
    strlen($v) == 0) { //don't change at all
                    
    continue;
                }
                if (
    strlen($v) < $config['pass_min_length']) {
                    
    $error[] = sprintf(_MEMBER_PROFILE_ERROR6$config[pass_min_length]);
                    continue;
                }
                if (
    strlen($v) > $config['pass_max_length']) {
                    
    $error[] = sprintf(_MEMBER_PROFILE_ERROR7$config[pass_max_length]);
                    continue;
                }
                if (
    $vars['pass0'] != $vars['pass1']){
                    
    $error[] = _MEMBER_PROFILE_ERROR8;
                    continue;
                }
                
    $field 'pass';
            }
            
    /// set value
            
    if ($field_type == 1){
                
    $user[$field] = $v;
            } elseif (
    $field_type == 2) {
                
    $ff $maf[$k];
                foreach ((array)
    $ff['validate_func'] as $func){
                    if (!
    strlen($func)) continue;
                    if (
    $err $func($v$ff['title'], $ff)){
                        
    $error[] = $err;
                    }
                }
                if (
    $ff['sql'])
                    
    $user[$k] = $v;
                else
                    
    $user['data'][$k] = $v;
            } else {
                
    fatal_error(sprintf(_MEMBER_PROFILE_ERROR9$k$field_type));
            }
        }
        if (!
    $error){
            
    $db->update_user($_amember_id$user);
            if (
    in_array('login'$fields_to_change))
                
    $_SESSION['_amember_login'] = $user['login'];
            
    $_SESSION['_amember_pass'] = $user['pass'];
        }
        return 
    $error;
    }
    Step 4: Modify the $custom_fields on line 4 of this function to be the custom field names you added to your form.

    I hope this works for you if you were facing the same issue. Good luck!
    -Marco
  13. RichII

    RichII New Member

    Joined:
    May 27, 2007
    Messages:
    8
    Hello,

    I'm having a little trouble with this same issue while trying to set up custom select fields.

    Instead of stacking three fields for birthday i.e. day month year, I'd like to run them together on one line. I created the three custom select fields, added some values, and set the visibility to no.

    I went into add_field_inc.html and looked at the code for a custom select field. It looks like this:
    Code:
    <select name="{$f.name|escape}" size="{$f.size|default:1}"
            id="f_{$f.name|escape}"
            {if $f.validate_func ne ""}class="required"{/if}
        >
        {html_options options=$f.options selected=$value}
        </select>
    So I set my statement up like this:

    Code:
    <tr>
        <th>Birth Date:</th>
        <td>
        <select name="day" size="1" id="f_day">{html_options options=[B]$f.options[/B] selected=user.day}</select>
    
        <select name="month" size="1" id="f_month">{html_options options=[B]$f.options[/B] selected=user.month}</select>
    
        <select name="year" size="1" id="f_year">{html_options options=[B]$f.options[/B] selected=user.year}</select>
        </td>
    </tr>
    The problem is that I can't seem to find the right way to call the values for $f.options

    Any help?

    Thanks,
    Rich
  14. shotoshi

    shotoshi Member

    Joined:
    Nov 28, 2008
    Messages:
    38
    I'm reading this with interest because I was hoping the admin CP would hold the answer of being able to group added fields by context.

    For my sign up page I want to add quite a few extra fields but I want them grouped, much in the same way as the 'Coupon' section is visually separated and the same way the form in aMember CP > Setup/Configuration > E-Mail has relative types of fields grouped.

    I feel this is a feature which should be added to future versions of the script, i.e. the ability in the Added Fields section to group the fields. Admins would be able to assign a group name, and all fields added would be grouped under the group name. They could also be re-ordered within each field group.

    Just an idea, but I feel this is an idea worth exploring, or at least selling as an add-on
  15. medix

    medix New Member

    Joined:
    Dec 17, 2008
    Messages:
    9
    does anybody know how to add multiple select drop-down boxes with this method? i manage to get it displayed and editable. the problem is that it only shows one of the selected options and not all of them. My code is like this right now

    Code:
    <select name="type" value="{$user.data.type|escape}" size="7" multiple>
    <option label="type1" value="1" {if $user.data.type eq "1"}selected{/if}>type1</option>
    <option label="type2" value="2" {if $user.data.type eq "2"}selected{/if}>type2</option>
    <option label="type3" value="3" {if $user.data.type eq "3"}selected{/if}>type1</option>
    </select>
    
    
    If the user choose only one option it works fine, but if they choose more than one, although the values are stored correctly in the database, only one is displayed when you visit your profile page. Im sure the problem is in the {if} part. That {if} works for single selection dropdowns, but not for multiple. do you know which one i should use?

    Thank you.
  16. celina

    celina Member

    Joined:
    Sep 9, 2008
    Messages:
    86
    this question never got answered. I'd also like to pass my custom field to an email. How can I identify it in an email template?
  17. dave123

    dave123 New Member

    Joined:
    Jul 24, 2009
    Messages:
    1
    i sent email to support about these questions. But no answer. anyone here know how to do this?

    1st Address: add a field(Street2) to this section - This is permanent address of the member
    2nd Address: in another section (Street1,Street2, City,State,Country) - This is mailing/temp address of the member

    now members cannot change their address in members' section. They can change only custom fields. Can we allow them to change their addresses in members area? If so how?
  18. appthemes

    appthemes New Member

    Joined:
    Dec 23, 2009
    Messages:
    9
    Amember address $fields_to_change not saving

    I wasn't able to see the members address info on the profile.php page even though I had the option selected in the admin backend. I ended up having to change profile.php to fix this.

    commented out this line:
    Code:
    $fields_to_change = (array)$config['profile_fields'];
    and replaced with this one:
    Code:
    $fields_to_change = array('pass0','name_f','name_l','email','street','city','zip','country','state');
    You also have to remove all the {if $fields_to_change.zip} type tags around the address fields on the profile.html template.

    I'm sure I missed some other option which automatically does this. This hack works though. ;-)



  19. kevinwhit

    kevinwhit New Member

    Joined:
    Dec 29, 2009
    Messages:
    3
    Can anyone tell me if its possible to add a 'survey' which uses the additional fields on any pages other than the sign up or profile page?
  20. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Is it necessary to store the survey answers in the users database?

    David

Share This Page