i've created a plugin (simple form) and this is the shortcode.php file:
<?php
add_shortcode('contact_form','contact_form');
function contact_form(){
if (isset($_POST['submit'])){
global $wpdb, $table_prefix;
$name = $_POST['name'];
$data = array('name'=>$name,'message'=>'message');
$wpdb->insert($table_prefix.'contact_form',$data,array('%s','%s'));
echo 'added';
}
?>
<form method="POST" action="" id="contact_form">
Name: <input type="text" name="name"><br>
<input type="submit" name="submit" value="submit">
</form>
<?php
}
when I submit the form, if I write sth in the text field, is says 'The page doesn't exist' but if i leave it empty, it submits the form. what is the problem? I have used this shortcode in a page.
See this question on the WordPress StackExchange site. In summary, WordPress gets confused by a field called name
. Try renaming it to (say) contact_name
.
Loads more detail here (also wpse).
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments