Different text in Login 'update profile' buttons

I am using the Login extra to allow people to update their user profiles.

The profiles contain a lot of information. People are asked a number of questions and choose an answer from radio buttons.

To make the update process less overwhelming I have placed each question on separate page.

People choose and answer to the first question and when they submit their answer they are moved on to the next page/question.

The button for submitting their answer on each page uses the required format for the Login extra:

value="[[!%login.update_profile]]"

By default this displays the text ‘Update profile’ in the button.

I know that I can change the text in this button by editing this line in the Lexicon.

$_lang['login.update_profile'] = 'Update Profile';

Ideally I would like to have more than one option for the text, depending on where the person is in the process.

ie: ‘Save and continue’ if they have more pages to complete
or ‘Save and review my answers’ if they have reached the end.

Does anyone know if this is possible?

I could be wrong, but I don’t think the value of the button is important.

<input type="submit" name="login-updprof-btn" value="[[!%login.update_profile]]" />

The important thing is, that the name corresponds to the value of the &submitVar property.
I assume you can just use any value you like.

@andytough , @halftrainedharry is right, only name attribute matters here(its transmission is checked in the snippet for compliance with &submitVar), you could use any possible value you like.

Thank you @himurovich and @halftrainedharry .

I had tried this without success.

I now think my problem is being caused by something I failed to mention in my initial post. The data I am updating is being stored in extra user fields created using @bobray s amazing classExtender, GetExtUsers. https://modx.com/extras/package/classextender

So my code starts with

[[!ExtUserUpdateProfile]]
[[!UpdateProfile? 
&submitVar=`login-updprof-btn`
&useExtended=`0`

Looking at the code for the ExtUserUpdateProfile snippet there is part that might be causing my issue?

$modx->lexicon->load('login:updateprofile');
$submission = isset($_POST['login-updprof-btn']) && ($_POST['login-updprof-btn'] == $modx->lexicon('login.update_profile'));

I have tried placing the submitVar in both snippet calls, but the data is still not updated.

It only gets updated if I set

value="[[!%login.update_profile]]"

Yes, here the value of the $_POST parameter is compared to the lexicon entry.
In the Login extra there is only a check if the $_POST parameter is not empty.

You’ll have to change the snippet ExtUserUpdateProfile to make it work:

//use
$submission = isset($_POST['login-updprof-btn']);
//or maybe
$submission = isset($_POST['login-updprof-btn']) && (!empty($_POST['login-updprof-btn']));

Thank you @halftrainedharry . I will report back on which option works. As this will affect the whole site, not just the bit I am working on at the moment I might not get to test it immediately.

When changing a snippet, it is usually a good idea to duplicate the snippet first and not change the original snippet directly (as your changes may get overwritten on the next update of the extra).

So I would duplicate ExtUserUpdateProfile and then adjust and test the new snippet. This way it also doesn’t affect the rest of your site.

1 Like

That is very good advice!

It is also important to mention that issue in the according repository. I don’t see a reason to compare the lexicon text, but maybe Bob has a reason for this.

@halftrainedharry the first option works well. I can now use submitVar. Thank you.

$submission = isset($_POST['login-updprof-btn']);

Hi @jako thanks for the suggestion. I have tested @halftrainedharry 's solution and it works. I’ll pass it on to @bobray in the repository and see if he has any thoughts on whether it is necessary or not.

I have mentioned this on the repository.

https://github.com/BobRay/ClassExtender/issues/7

Well actually with this change you still have to use login-updprof-btn for the name of the submit button. If you want to support the property submitVar as well (to allow for buttons with a different name-attribute), then the code probably has to look like this:

$submitVar = $modx->getOption('submitVar',$scriptProperties,'login-updprof-btn');
$submission = isset($_POST[$submitVar]);

Hi @halftrainedharry . Thanks. Your original solution allowed me to change the value of the button. It seems that there was not a problem with submitVar after all, but that I had made a typo in my submitVar entry, so sorry, that was a bit of a red herring!

It’s been a while, but I think my reasoning was that if you wanted to change the text of the button, the best place to do it would be in Lexicon Management. That way you wouldn’t need to modify the code, and the change would survive upgrades to the package.

Let me know if you think I’m off base on this.

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.