Skip to:
Content
Pages
Categories
Search
Top
Bottom

Edit input tag profile field_1?

  • Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    Is there any way to edit the input tag for profile field_1 (fullname) on the signup form?

    I wanted to use the javascript I found here to autogenerate username from fullname on typing, but it requires a way to add onkeyup=”copyinput()” to the input tag, like this:

    `<input type=”text” name=”field_1″ id=”field_1″ value=”” onkeyup=”copyinput()” />

    Unfortunately the input tag for field_1 is generated with very obscure php code split over several files. I can’t figure it out.

    Or will this be possible in the new template system in version 1.1?

    I already have another solution to generate username from fullname, but this javascript solution would be cleaner and less intrusive.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    I see the html for the xprofile input fields is in function get_edit_html in bp-xprofile-classes.php:

    switch ( $this->type ) {
    case 'textbox':
    $html .= '<div class="signup-field">';
    $html .= '<label class="signup-label" for="field_' . $this->id . '">' . $asterisk . $this->name . ':</label>';
    $html .= $this->message . '<input type="text" name="field_' . $this->id . '" id="field_' . $this->id . '" value="' . attribute_escape( $this->data->value ) . '" />';
    $html .= '<span class="signup-description">' . $this->desc . '</span>';
    $html .= '</div>';
    break;

    So I guess I could add onkeyup=”copyinput()” there, but then all xprofile fields will get that. Would that mess up the system? The Javascript refers to the fields by ID.

    According to Jeff Sayre this method will be deprecated in version 1.1, but I need a temporary solution before I make the switch.

    Trying that now…

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

    The hack in function get_edit_html works.

    I had to slightly edit the javascript. ‘-’ is not accepted in usernames:

    function copyinputuser()
    {
    var tmp = document.getElementById('field_1').value;
    tmp = tmp.toLowerCase().replace(/^\s+|\s+$/g, "").replace(/[_|\s]+/g, "");
    tmp = tmp.replace(/[^a-z0-9-]+/g, "").replace(/[-]+/g, "").replace(/^-+|-+$/g, "");
    document.getElementById('user_name').value = tmp;
    }

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

You must be logged in to reply to this topic.