Reputation: 9
I need some help, im trying to do a wp_insert_post
with a htmlform (php and wordpress). I keep getting a 500 server error and i dont understand why, can you please help me? (the prints and echoes is for testing some stuff).
<?php
print_r($_POST);
if( 'POST' == $_SERVER['REQUEST_METHOD'] ){
print((isset ($_POST['title1'])));
// Do some minor form validation to make sure there is content
if (isset ($_POST['title1'])) {
$title = $_POST['title1'];
} else {
echo 'fyll i';
}
if (isset ($_POST['description'])) {
$description = $_POST['description'];
} else {
echo 'fyll i';
}
if (isset ($_POST['message'])) {
$message = $_POST['message'];
} else {
echo 'fyll i';
}
$tags = $_POST['post_tags'];
echo('ny entry');
print_r($new_post);
$new_post = array(
'post_title' => $title,
'post_content' => $message,
'post_name' => $description,
'post_status' => 'publish',
'post_type' => 'omdmen'
);
print_r($new_post);
$new_post = wp_insert_post($new_post);
}
echo('finished');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div id="postbox">
<form id="new_post" name="new_post" method="post" action="votepost.php">
<p><label for="title">Ide</label><br />
<input type="text" id="title" value="" tabindex="1" size="20" name="title1" />
</p>
<p><label for="description">Hantverk</label><br />
<input type="text" id="description" value="" tabindex="1" size="20" name="description" />
</p>
<p><label for="message">Budskap</label><br />
<input type="text" id="message" value="" tabindex="1" size="20" name="message" />
</p>
<input type="submit" value="OK" tabindex="6" id="submit" name="submit" />
</form>
</div>
</body>
</html>
Upvotes: 0
Views: 1108
Reputation: 56
Are the $title, $description elsewhere in the code initiated? When the code reached the '$new_post = array' line maybe the variables doesn't exists.
What happens if you set the variables on the top of your code like this:
$title = 'This is my title';
$message = 'This is my message';
$description = 'This is my description';
Does it get saved?
Upvotes: 0