admin管理员组文章数量:1314454
Bit of a strange one here.
I have a website setup using external json data to show football/soccer match details.
An example is here /match-result/365972/
the numeric ID is used to get the data from the external json.
What we would like is for people to be able to leave comments and images from the game under each match.
I have setup a form
<form method="POST" action="#">
<?php wp_editor($content,"content", array('textarea_rows'=>12, 'editor_class'=>'content_class')); ?>
<input type="hidden" name="name" value="<?php echo $current_user->user_login; ?>"/>
<input type="hidden" name="gameid" value="<?php echo $match_id; ?>"/>
<input type="submit" name="submitComment" value="submit" />
</form>
and within the page i have the following code to check for the form submission
$default = array(
'name' => '',
'content' => '',
'moderation' => '0',
'gameid' => '',
);
$item = shortcode_atts( $default, $_REQUEST );
if($_POST['submitComment']) {
echo 'something fun';
$wpdb->prepare($wpdb->insert( $table_name, $item ));
$comment_success = '1';
global $comment_success;
}
The form is visible on the page, but when you press submit there is a 404 error, the url is correct but the page doesn't exist.
I am wondering what I have done wrong?
I am using a plugin called PHPCode Snippets by XYZ to run the php on the page.
The full snippet (less a few personal json details) can be found at
Hopefully someone can point me in the right direction.
-Chalkie
Bit of a strange one here.
I have a website setup using external json data to show football/soccer match details.
An example is here https://www.husupporters.club/match-result/365972/
the numeric ID is used to get the data from the external json.
What we would like is for people to be able to leave comments and images from the game under each match.
I have setup a form
<form method="POST" action="#">
<?php wp_editor($content,"content", array('textarea_rows'=>12, 'editor_class'=>'content_class')); ?>
<input type="hidden" name="name" value="<?php echo $current_user->user_login; ?>"/>
<input type="hidden" name="gameid" value="<?php echo $match_id; ?>"/>
<input type="submit" name="submitComment" value="submit" />
</form>
and within the page i have the following code to check for the form submission
$default = array(
'name' => '',
'content' => '',
'moderation' => '0',
'gameid' => '',
);
$item = shortcode_atts( $default, $_REQUEST );
if($_POST['submitComment']) {
echo 'something fun';
$wpdb->prepare($wpdb->insert( $table_name, $item ));
$comment_success = '1';
global $comment_success;
}
The form is visible on the page, but when you press submit there is a 404 error, the url is correct but the page doesn't exist.
I am wondering what I have done wrong?
I am using a plugin called PHPCode Snippets by XYZ to run the php on the page.
The full snippet (less a few personal json details) can be found at https://pastebin/tYWJ9q60
Hopefully someone can point me in the right direction.
-Chalkie
Share Improve this question asked Jan 2, 2021 at 12:12 ChalkieChalkie 92 bronze badges1 Answer
Reset to default 0I have managed to fix it by just changing my form data from
<form method="POST" action="#">
to
<form method="POST" action="<?php the_permalink(); echo $match_id; ?>?success=yes">
i am using the ?success=yes tag so that the form is no longer shown but just shows a moderation message instead.
本文标签: phpForm from within a page
版权声明:本文标题:php - Form from within a page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741871672a2402231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论