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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

I 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