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?