• Resolved andrewwatson

    (@andrewwatson)


    Hi all, I am out of my depth but with something simple (I hope) and wondered if the forum could help.

    I am using WordPress and contact form 7 and I use Redirection for Contact Form 7 plugin which manages what happens after the form is filled in.

    It has a space for JavaScript to be run when the form is sent.

    I am making a form to update a user role if they fill out the form, and this form is only available if they are already logged in. so I thought the easiest way would be to use java script to:

    change current (logged in) user role to new role

    or even simpler

    let role (of logged in user) = new role

    I don’t know JavaScript at all, but I thought I could google it and piece it together, but like all things there are pages and pages about the keyword and not my specific problem topic, so much that I haven’t even been able to get even a few bits of code to try and put it together…

    Any help would be appreciated!!, even just somewhere to see clearly how to use JavaScript and user roles with WordPress, so i can learn how to do it myself.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    JavaScript cannot change roles directly, as it runs in the client. Altering roles needs to be done server side. What you can do is have the script send an Ajax request to the server and have the Ajax handler make the change.

    CF7 sends form submittal notifications from the server. I’ll bet there’s an action that fires within CF7 code when the form is submitted that you could hook into to effect the change instead of going through a separate Ajax request. It’d be a lot cleaner this way. For the specific hook, I suggest you ask in the dedicated CF7 support forum.
    https://www.ads-software.com/support/plugin/contact-form-7/

    Thread Starter andrewwatson

    (@andrewwatson)

    Ok. Surprisingly that made a lot of sense.

    Thanks for your help!

    I’ll ask under the CF7 area of the forum and if I get an actual solution, to my particular problem, I’ll come back here and update it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change user role with script’ is closed to new replies.