how to submit a form in wordpress

2019-07-09 01:52发布

问题:

I am using wordpress 3.3.1 with twentyten theme,

i have created a plugin to create a custom form,

i have successfully installed this in wordpress,

my plugin file code is as follows

<?php
function guest_event_form()
{ 

if(isset($_POST['submit']) and $_POST['action']=='new registration')
{

    global $wpdb;
    $wpdb->query("Insert Query...");
}
else
{
?>
<form method="POST" action="" name="guest_registration" enctype="multipart/form-data"> 
<input type="text" id="name" name="name" value="">
<input type="submit" name="submit" value="Register Me Now"/>
<input type="hidden" name="action" value="new registration" />
</form>
<?php
}
}
add_shortcode( 'guest_event_form', 'guest_event_form' );
?>

whenever i am submitting this form, i returns to same page with search results,

so i guess the problem whenever i submit this form, wordpress takes this submit action as a search action, and it starts search

how do i overcome this problem??

回答1:

The Problem is because of following form element's id

<input type="text" id="name" name="name" value="">

name is one of the wordpress internal variable