2 days ago I asked this then I tried to work on my code to be able to understand how ajax and php work and now I have a new issue that, probably would be easily solved.
These are my codes:
<?php
/*
Template Name: Nuovo form
*/
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
<script src="https://malsup.github.com/jquery.form.js"></script>
<script>
// wait for the DOM to be loaded
$(document).ready(function() {
// bind 'myForm' and provide a simple callback function
$('#myForm').ajaxForm(function() {
alert("Thank you for your comment!");
});
});
</script>
<?php wp_head();?>
</head>
<body>
<form id="myForm" action="<?php echo get_template_directory_uri();?>/nuovoform/comment.php" method="post">
Name: <input type="text" name="name" />
Comment: <textarea name="comment"></textarea>
<input type="submit" value="Submit Comment" />
</form>
</body>
</html>
Then this is my Comment.php
<?php
// This is comment.php content
$nuovoform = 0;
$nuovocommento = 1;
if ( isset( $_POST['name'] )){
$nuovoform = $_POST['name'];}
if ( isset( $_POST['comment'] )){
$nuovocommento = $_POST['comment'];}
update_post_meta($post->ID,'varcontrollo',$nuovoform);
$controlliamo = get_post_meta($post->ID, 'varcontrollo', true);
?>
‘varcontrollo’ is a custom meta field created using Custom Field Template plugin.
What I’m trying to do is use the form I created to store the result inside my custom field.
If I try to browse to comment.php it says this:
Fatal error: Call to undefined function update_post_meta() in
D:\Locali\xampp\htdocs\wp-content\themes\slotlandia\nuovoform\comment.php
on line 8
Probably i have to ‘import’ WordPress ‘global’ variables but I don’t know what have I to write.
Is there anyone who can help me?
Thank you very much.