0

I've searched two day's all over the web and forums to find the solution for my problem (this site as well). Some questions here were similar but didn't help me at all. Ok to get to the point, I'd be very thankful if someone could asist me.

I've made a guestbook in my custom wordpress theme. This guestbook shows up just the way I wanted. Everything is set in phpMyAdmin and works. Only problem i'm having is the form action="" doesn't work. When I leave it empty and I fill in the guestbook form, it just shows a blank content.

What can I fill in between these quotes action="" Answers on sites and forums say leave it empty, but it doesn't give me the results I want. When I fill in the guestbook form it should show the message when someone submits.

Here is my code, perhaps i'm doing something wrong?

    <?php 

    mysql_connect("blablabla", "blablabla", "blablabla");
    mysql_select_db("blablabla");

    /***************************************************************************************************************/
    //  Form and add stuff area

    echo "<strong>Laat anderen uw mening weten over Bed & Breakfast Nerja</strong>";

    if ($_POST['bericht_btn']) {
            $naam = strip_tags($_POST['naam']);
            $email = strip_tags($_POST['email']);
            $bericht = strip_tags($_POST['bericht']);

            if ($naam && $email && $bericht) {

                    $tijd = datum("h:i A");
                $datum = datum("F d, Y");
                $ip = $_SERVER['REMOTE_ADDR'];

                // Voeg toe aan database
                mysql_query("INSERT INTO gastenboek VALUES (
                        '', '$naam', '$email', 'bericht', 'tijd', 'datum', 'ip'
                )");

                echo "Bedankt. Uw bericht is succesvol toegevoegd aan ons gastenboek.";
            }
            else
                echo "Niet alle velden waren ingevuld.";
            }

            echo "<form action='' method='post' id='form_guestbook'>
                <table><br />
                        <tr>
                            <td>Naam:</td>
                            <td><input type='text' name='naam' style='width: 200px;' /></td>
                        </tr>
                        <tr>
                            <td>Email:</td>
                            <td><input type='text' name='email' style='width: 200px;' /></td>
                        </tr>
                        <tr>
                            <td>Bericht:</td>
                            <td><textarea name='bericht' style='width: 450px; height: 100px; margin-bottom: 20px;'></textarea></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td><input type='submit' name='bericht_btn' value='Plaats bericht' /></td>
                        </tr>
                </table>
            </form>
            <br />";

    /***************************************************************************************************************/
    //  Display stuff area

    //echo "Alle gedeelde meningen";
        echo "<div style='color: red; font-size: 20px;'>Het gastenboek werkt nog niet compleet. Hier wordt aan gewerkt.</div>";                       
    $query = mysql_query("SELECT * FROM gastenboek ORDER BY id DESC");
    $numrows = mysql_num_rows($query);

    echo "<hr />";

    if($numrows > 0){
            while ( $row = mysql_fetch_assoc($query) ) {
                    $id = $row['id'];
                $naam = $row['naam'];
                $email = $row['email'];
                $bericht = $row['bericht'];
                $tijd = $row['tijd'];
                $datum = $row['datum'];
                $ip = $row['ip'];

                $bericht = nl2br($bericht);

                echo "<div>
                        Bericht van <strong>$naam</strong> op <strong>$datum</strong> om <strong>$tijd</strong> <br />
                        $bericht
                        </div><hr />";
                }
            }
            else
                    echo "Er zijn geen berichten gevonden.";

    /***************************************************************************************************************/

    mysql_close();

?>

This code is in the gastenboek.php (means guestbook.php in dutch) and it's included in my page.php and is shown only for a certain page (the guestbook page).

    <?php
      if ( is_page('gastenboek') ) {
    include 'gastenboek.php';
  }
    ?>

The end page url is as followed mywebsite.nl/wordpress/gastenboek (seo friendly url)

Thanks if someone could assist/help me, I think the problem isn't that big, but I just can't seem to find the solution thanks to my lack of knowledge with custom forms that are compatible with wordpress.


Ok i'm getting closer in solving the problem. I already tried the guestbook without wordpress by just using a guestbook.php file on my server. Here I was able to use

    <form action="../guestbook.php"

Guess what, it worked xD ! So the problem is one of the following things or probably both of them:

  • Where should I place my code in the wordpress .php files ? (currently it's in the page.php file where I have a if statement to include the guestbook.php only for a certain page)

    if ( is_page('name of a page') ) {
                                  include 'guestbook.php';
                            }
    
  • What must I type between the quotes of action="" ? (I've tried many different things, path to guestbook.php, keeping it empty, using the permalink code and none worked so far for me)

4

2 回答 2

0

问题解决了 !!!

我必须做以下事情:将 ID 添加到表单并更改输入字段的名称,因为它与 wordpress 冲突。

我之前更改了输入类型的名称,但它不起作用。我也只是忘记为此代码更改它:

    $name = strip_tags($_POST['formname']);
                            $email = strip_tags($_POST['formemail']);
                            $message = strip_tags($_POST['formmessage']);

不管怎样,谢谢你的回复尼尔吉拉迪

于 2013-10-16T09:20:36.277 回答
0

改变:

if ($_POST['bericht_btn']) {

至:

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

单击提交不会发布提交的名称属性。

或者,您可以使用隐藏输入。为此,您可以将其放入您的表单中:

<input type="hidden" name="submitted" />

然后在您的表单处理程序中使用此检查:

if (isset($_POST['submitted']))) {

至于表单的action属性,应该设置为处理它的脚本的url。看起来显示表单的脚本与处理表单的脚本相同,因此如果此脚本被称为“foo.php”,您可以将操作属性设置为“/foo.php”。

于 2013-10-16T00:45:41.320 回答