Forum
Add member tag on profile form submit
Can I use perch_member_add_tag when a member updates their profile?
I want to limit the amount of times members can change their name to once a month. So the idea is when they submit the profile form it adds a tag to the member with a one month expiry, and I check for that tag before outputting the form in the first place.
To handle the form submission specifically, you'd need to register a new app with your code and post the form to both Members and your app.
I had a quick look at the API section but not sure I have the time to get my head around making an app. Would it not work to simply point the redirect for the form to a PHP page which includes the add_tag line and then redirects back to the original page?
Yes, you could do that if you're happy to test that the correct form has been submitted yourself.
I've attempted this but for some reason it won't recognise the isset name_change (works ok if I remove that).
profile.html
update-name.php
Perch manages the forms for you, so there won't actually be a field called
name_change
.Ah. So how can I check the form was submitted before confirming the tag addition?
Stephen, in the success tag use perch_layout and add your perch_member_add_tag() in the layout.
You can specify a custom prefix on the form tag - that should give you predictable field names.
I added prefix="name" to the profile form.
The hidden field now outputs as:
I have tried both the following in my script and neither works:
Have you looked to see what you actually have in
$_POST
?It gives an empty array
Do you have any server side redirects that might be dropping the POST?
No, I don't think so.
It's worth checking. Some people use a redirect to e.g. strip the
.php
file extension off the URL.Double checked and no redirects in place. Cleared my .htaccess and tried again, still no joy.
Is there anything else that could be dropping POST?
Is this the page
/account/update-name.php
? If so, you're not posting to it. You're posting back to your first page and then redirecting with thenext
attribute.That's it - I just had to change
next
toaction
. Thank you.