0

I've been having trouble getting a front-end profile template to save any data. It was quite complex so I've gone back to a base install of Craft with no custom fields for a User.

Using the example code from the docs it still doesn't save any data. http://buildwithcraft.com/docs/templating/user-profile-form

This is running the full version of Craft on localhost.

I have a custom route of /profile set to a template called 'profile'.

Loading the page loads all currently stored data exactly the same as the CP.

Submitting the form reloads the page but none of the input data is saved and redisplayed. Going to the CP also shows nothing was saved.

After a few hours of trouble-shooting I discovered, on submit from the front-end template, the saveUser method was not running. It was from the CP.

Adding action="{{ siteUrl }}" to the form gets it working. But oddly then introduces the front controller in to the URL after submit, eg. http://localhost/index.php/profile.

There's no mention in the example code of a form requiring an action value. I can't work out why the example code doesn't work or why I need action. I'd rather not have the pretty URLs messed up.

Help?

<h1>Profile</h1>

<form action="{{ siteUrl }}" method="post" accept-charset="UTF-8" enctype="multipart/form-data">

    {{ getCsrfInput() }}

    <input type="hidden" name="action" value="users/saveUser">
    <input type="hidden" name="redirect" value="profile">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">

    <fieldset> 
        <legend class="visually-hidden">Personal details</legend>

        <label for="firstName">First name <span class="required">*</span></label>
        <input id="firstName" type="text" name="firstName" value="{{ currentUser.firstName }}" placeholder="Jane" required="required" aria-required="true" autofocus="autofocus">

   </fieldset>

    <input type="submit" value="Save Profile">
</form>

Update 10-08-2015

The profile form submitting seems to be a red-herring. When installing Craft I couldn't get it to work with clean URLs so I edited Apache's config to set 404s to redirect to crafts index.php. I'd since forgot. Local config:

  • Mac OS X 10.10.4
  • MAMP (not pro)

By default MAMP has AllowOverride None. That was stopping the .htaccess file from working. I'm using vhosts so I've manually set this in the vhost config. Another gotcha is Crafts config of omitScriptNameInUrls and usePathInfo. Craft caches test results for 24 hours, so I had to clear the cache before my updated vhost config worked.

<Directory "/path/to/craft/public">
    Options FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow From All
</Directory>

The title of this SE question is all wrong now but it's valuable info. OK to change? I'd also say this is a common enough set-up to be in the official docs?

  • That's... weird. Are all other URLs working on your site (submitting from the CP, etc.)? – Brad Bell Aug 7 '15 at 19:02
  • Yep, everything works fine in the CP. – Elliot Lewis Aug 9 '15 at 20:27
1

The answer is now included in the question. Don't be a dingbat and make sure MAMP or Apache (or whatever webserver you're using) is configured properly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.