This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

joel11665
joel11665

Hi,

i manage to extend the User plugin by adding new fields through this solution :

$model->hasOne['profile'] = ['MyCompany\Profile\Models\Profile'];

Everything works fine in the backend, the only thing i miss is the frontend component, i can't populate my form with the new fields, any idea ?

my account page :


title = "Account"
url = "/account/:code?"
layout = "default"
is_hidden = 0

[account]
redirect = "home"
paramCode = "code"
==
{% component 'account' %}

and view overridden (First name is a new field) :

{{ form_ajax('onUpdate', { model: user }) }}
<div class="form-group">
    <label for="accountName">Full Name </label>
    <input name="name" type="text" class="form-control" id="accountName" value="{{ form_value('name') }}">
</div>

<div class="form-group">
    <label for="accountEmail">Email</label>
    <input name="email" type="email" class="form-control" id="accountEmail" value="{{ form_value('email') }}">
</div>

<div class="form-group">
    <label for="accountPassword">New Password</label>
    <input name="password" type="password" class="form-control" id="accountPassword">
</div>

<div class="form-group">
    <label for="accountPasswordConfirm">Confirm New Password</label>
    <input name="password_confirmation" type="password" class="form-control" id="accountPasswordConfirm">
</div>

<div class="form-group">
    <label for="firstName">First Name dsd</label>
    <input name="first_name" type="text" class="form-control" id="firstName" value="{{ form_value('profile.first_name') }}">
</div>

<button type="submit" class="btn btn-default">Save</button>

{{ form_close() }}

Last updated

KurtJensen
KurtJensen

User plugin has 'name' ( first name ) and 'surname' ( last name ) built in.

To override the register form use:

<form
    data-request="onRegister">
    <div class="form-group">
        <label for="registerName">First Name</label>
        <input name="name" type="text" class="form-control" id="registerName" placeholder="Enter your first name">
    </div>
    <div class="form-group">
        <label for="registerSurname">Last Name</label>
        <input name="surname" type="text" class="form-control" id="registerSurname" placeholder="Enter your last name">
    </div>

    <div class="form-group">
        <label for="registerEmail">Email</label>
        <input name="email" type="email" class="form-control" id="registerEmail" placeholder="Enter your email">
    </div>

    <div class="form-group">
        <label for="registerPassword">Password</label>
        <input name="password" type="password" class="form-control" id="registerPassword" placeholder="Choose a password">
    </div>

    <button type="submit" class="btn btn-default">Register</button>
</form>

To override the update form use:

{{ form_ajax('onUpdate', { model: user }) }}

    <div class="form-group">
        <label for="accountName">First Name</label>
        <input name="name" type="text" class="form-control" id="accountName" value="{{ form_value('name') }}">
    </div>

    <div class="form-group">
        <label for="accountSurname">Last Name</label>
        <input name="surname" type="text" class="form-control" id="accountSurname" value="{{ form_value('surname') }}">
    </div>

    <div class="form-group">
        <label for="accountEmail">Email</label>
        <input name="email" type="email" class="form-control" id="accountEmail" value="{{ form_value('email') }}">
    </div>

    <div class="form-group">
        <label for="accountPassword">New Password</label>
        <input name="password" type="password" class="form-control" id="accountPassword">
    </div>

    <div class="form-group">
        <label for="accountPasswordConfirm">Confirm New Password</label>
        <input name="password_confirmation" type="password" class="form-control" id="accountPasswordConfirm">
    </div>

    <button type="submit" class="btn btn-default">Save</button>

{{ form_close() }}
joel11665
joel11665

Nope that's not what i m expected , to be more clear there is a new table mycompany_profile with all new entries (first_name, last_name, job_title and so on) and it is hasOne relation whith User . Just need to populate my form with these new fields .

KurtJensen
KurtJensen

So you need to do something like the profile plugin: https://octobercms.com/plugin/kurtjensen-profile

There is a video on doing that: https://vimeo.com/108040919

Last updated

joel11665
joel11665

i actually follow this video and so i have to buy your plugin to fond the solution ;)

KurtJensen
KurtJensen

If you really want to learn then keep reading docs, searching Internet and spend a lot of time playing with code. I'm not saying I am unwilling to help. I frankly don't have much time right now and your question is not detailed enough ( model code examples, etc. ) for me ( or others ) to answer your question.

If you just need to get it done then $10 will get you the plugin and support that will likely complete your task.

It's really a time vs money thing for most people.

joel11665
joel11665

Hey Kurt

you were right, your plugin was very helpfull ;)

Michael Skweres
Michael Skweres

@Kurt is your plugin related to native user plugin? I mean by fields etc. or is it a separate system? Additionally thank you for code bit it helped me a lot. Would you consider posting on how to update values in profile using dropdown list of prepopulated values? Like.. gender => male, female etc.

KurtJensen
KurtJensen

@Michael Skweres Yes it is.

Are you doing this in frontend component, backend, your own plugin, some page code? Are you wanting users to do this on signup?

I use the plugin for a private members only site so I always set the gender in the backend and never realized until you mentioned it that I did not provide a way for users to specify their gender on the frontend. I will have to do that. I tried just adding the fields in a partial for the user plugin just now and I can not get it to save the related values. Looks like I may need to extend the user plugins account component with my own special one to include the related fields.

Any clarification you can give me about what you are trying to accomplish may help me provide a solution tailored to your needs.

Thank you for contacting me about this.

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.