How to create wordpress new user from html form?












0















This is my first attemp to create a wordpress plugin.
The form part works, and an email is sent to site admin.
But the new wordpress user isnt created.



Sorry if this is obvoious, but I havent coded before and am trying to marry up bits of code.



I assume the problem is that the form isnt in a way that the user creation component can understand.



function html_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br/>';
echo '<input type="text" name="username" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["username"] ) ? esc_attr( $_POST["username"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br/>';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject (required) <br/>';
echo '<input type="text" name="finance-subject" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["finance-subject"] ) ? esc_attr( $_POST["finance-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br/>';
echo '<textarea rows="10" cols="35" name="finance-message">' . ( isset( $_POST["finance-message"] ) ? esc_attr( $_POST["finance-message"] ) : '' ) . '</textarea>';
echo '</p>';









share|improve this question

























  • Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

    – anmari
    Nov 22 '18 at 5:09











  • While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

    – anmari
    Nov 22 '18 at 5:13













  • Where is the form processing code/function?

    – zipkundan
    Nov 22 '18 at 8:08











  • function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

    – Speedy
    Nov 22 '18 at 8:33
















0















This is my first attemp to create a wordpress plugin.
The form part works, and an email is sent to site admin.
But the new wordpress user isnt created.



Sorry if this is obvoious, but I havent coded before and am trying to marry up bits of code.



I assume the problem is that the form isnt in a way that the user creation component can understand.



function html_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br/>';
echo '<input type="text" name="username" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["username"] ) ? esc_attr( $_POST["username"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br/>';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject (required) <br/>';
echo '<input type="text" name="finance-subject" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["finance-subject"] ) ? esc_attr( $_POST["finance-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br/>';
echo '<textarea rows="10" cols="35" name="finance-message">' . ( isset( $_POST["finance-message"] ) ? esc_attr( $_POST["finance-message"] ) : '' ) . '</textarea>';
echo '</p>';









share|improve this question

























  • Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

    – anmari
    Nov 22 '18 at 5:09











  • While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

    – anmari
    Nov 22 '18 at 5:13













  • Where is the form processing code/function?

    – zipkundan
    Nov 22 '18 at 8:08











  • function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

    – Speedy
    Nov 22 '18 at 8:33














0












0








0


1






This is my first attemp to create a wordpress plugin.
The form part works, and an email is sent to site admin.
But the new wordpress user isnt created.



Sorry if this is obvoious, but I havent coded before and am trying to marry up bits of code.



I assume the problem is that the form isnt in a way that the user creation component can understand.



function html_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br/>';
echo '<input type="text" name="username" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["username"] ) ? esc_attr( $_POST["username"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br/>';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject (required) <br/>';
echo '<input type="text" name="finance-subject" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["finance-subject"] ) ? esc_attr( $_POST["finance-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br/>';
echo '<textarea rows="10" cols="35" name="finance-message">' . ( isset( $_POST["finance-message"] ) ? esc_attr( $_POST["finance-message"] ) : '' ) . '</textarea>';
echo '</p>';









share|improve this question
















This is my first attemp to create a wordpress plugin.
The form part works, and an email is sent to site admin.
But the new wordpress user isnt created.



Sorry if this is obvoious, but I havent coded before and am trying to marry up bits of code.



I assume the problem is that the form isnt in a way that the user creation component can understand.



function html_form_code() {
echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
echo '<p>';
echo 'Your Name (required) <br/>';
echo '<input type="text" name="username" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["username"] ) ? esc_attr( $_POST["username"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Email (required) <br/>';
echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Subject (required) <br/>';
echo '<input type="text" name="finance-subject" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["finance-subject"] ) ? esc_attr( $_POST["finance-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Your Message (required) <br/>';
echo '<textarea rows="10" cols="35" name="finance-message">' . ( isset( $_POST["finance-message"] ) ? esc_attr( $_POST["finance-message"] ) : '' ) . '</textarea>';
echo '</p>';






wordpress






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 6:57







user7154703

















asked Nov 22 '18 at 4:41









SpeedySpeedy

11




11













  • Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

    – anmari
    Nov 22 '18 at 5:09











  • While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

    – anmari
    Nov 22 '18 at 5:13













  • Where is the form processing code/function?

    – zipkundan
    Nov 22 '18 at 8:08











  • function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

    – Speedy
    Nov 22 '18 at 8:33



















  • Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

    – anmari
    Nov 22 '18 at 5:09











  • While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

    – anmari
    Nov 22 '18 at 5:13













  • Where is the form processing code/function?

    – zipkundan
    Nov 22 '18 at 8:08











  • function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

    – Speedy
    Nov 22 '18 at 8:33

















Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

– anmari
Nov 22 '18 at 5:09





Hi speedy, first off I suggest just get the action to fire when and ONLY when you want. Maybe just issue a debug to the error_log so yu can see when it is firing. Admin_init fires EVERY time an access is made to a wp admin page. NOt a good choice for inserting a user. See codex.wordpress.org/Plugin_API/Action_Reference/admin_init

– anmari
Nov 22 '18 at 5:09













While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

– anmari
Nov 22 '18 at 5:13







While testing consider having the "insert user code" to be triggered from a button in html, so you can then dump the response. I'd dump what is being returned - there maybe info there telling you what is wrong. I'd also specify as little fields as you can get away with in the beginning. WP will probably fill in the blanks. Once you have both aspects working, then you can put them together. Start with very small steps.

– anmari
Nov 22 '18 at 5:13















Where is the form processing code/function?

– zipkundan
Nov 22 '18 at 8:08





Where is the form processing code/function?

– zipkundan
Nov 22 '18 at 8:08













function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

– Speedy
Nov 22 '18 at 8:33





function html_form_code() { echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">'; echo '<p>'; echo '<p>'; echo 'Your Email (required) <br/>'; echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p>'; echo '<p><input type="submit" name="finance-submitted" value="Send"></p>'; echo '</form>'; }

– Speedy
Nov 22 '18 at 8:33












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424002%2fhow-to-create-wordpress-new-user-from-html-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424002%2fhow-to-create-wordpress-new-user-from-html-form%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?