I have a problem with posting form data to same page to process it in Wordpress. I have created a shortcode named [lwCSForm] that works and spits out the form on the page its been added to. The problem is when I press submit the page wont notice the $_POST['submit'] variable and my code cant process the data.
I have tested to use these actions in the form:
action="php echo $_SERVER['PHP_SELF']"(I can't get the php tag to work here)action="php echo $post->post_title"(I can't get the php tag to work here)and even direct write the page name:
action="about"
This is the function to display the form through shortcode on a page:
function DisplayCustomSettingsForm_shortcode() {
global $post;
if( !is_user_logged_in() ){
echo '<div class="lwCSForm-notloggedin">
<p> Please login to view the content! </p>
</div>';
return;
}
if( isset( $_POST['submit'] ) )
{
echo "The submit button is pressed and has data";
/* Code to update customers settings, like avatar, email, username */
} else {
$phpself = $post->post_title; // get the current page
?><br />
<!-- LwCSForm Plugin-->
<section id="lwCSForm-wrapper">
<form name="lwCSForm" id="lwCSForm" method="post" action="<?php $phpself ?>" autocomplete="on">
Name: <input type="text" name="realname" placeholder="Your Name" >
Sitename: <input type="text" name="username" placeholder="Username" >
E-mail: <input type="text" name="email" placeholder="E-mail" >
Avatar: <input type="text" name="avatar" placeholder="Avatar" >
<input type="submit" >
</form>
</section>
<!-- END LwCSForm Plugin-->
<br /> <?php
}
}
add_shortcode( 'lwCSForm', 'DisplayCustomSettingsForm_shortcode');
Picture of the added form with the shortcode
Why wont wordpress process this information? and a disclaimer again. I can't get the php tags to print here but they are there in the source.
