Jump to content

[SOLVED] Noob needs help with refresh-on-click-and-change-text thingy :D


Emaziz

Recommended Posts

Hi,

 

I don't really have any experience in PHP I'm just trying to edit scripts I find. I was trying to make a comment box, where when you hit submit, the whole form will disappear and a text like "Thanks" will appear in it's place. Here's what I tried:

    <?php
    if ($_post["user"]!="") 
    	echo "<p>Takk, kommentaren din har blitt sendt.</p>"; 
    else 
    echo "
    <p> Her kan du sende inn en kommentar til oss om du er fornøyd med servicen. <br /><form action='#' method='get'>
    <label for='name'>Brukernavn: </label>
    <input type='text' id='name' name='user' maxlength='32' size='14' />
    <label for='text'>Kommentar: </label>
    <textarea rows='7' cols='12' maxlength='256'>Skriv her</textarea>
    <input type='submit' value='Send inn' /></form></p>";
?>

 

Any advise is highly appreciated. Thanks. :)

there are some errors with your php structure you need to add { } brackets to you if statements. Like this:

 

<?php

    if ($_post["user"]!="") {

    echo "<p>Takk, kommentaren din har blitt sendt.</p>";

    } else {

    echo "

    <p> Her kan du sende inn en kommentar til oss om du er fornøyd med servicen. <br /><form action='#' method='get'>

    <label for='name'>Brukernavn: </label>

    <input type='text' id='name' name='user' maxlength='32' size='14' />

    <label for='text'>Kommentar: </label>

    <textarea rows='7' cols='12' maxlength='256'>Skriv her</textarea>

    <input type='submit' value='Send inn' /></form></p>";

}  ?>

Thanks. It makes no difference though. Even though user does not equal to "" (which is blank?) the form still shows.

 

Change this:

if ($_post["user"]!="")

 

To:

if (isset($_POST["user"]) and trim($_POST["user"])!="")

 

Also, change:

<form action='#' method='get'>

 

To:

<form action='#' method='post'>

 

Does it help you?

 

 

Err. Not really. When I hit Submit nothing happens. It tried to load the page for about 30 sec then it comes an error that says site cannot be shown. New code is:

   <?php
    if (isset($_POST["user"]) and trim($_POST["user"])!="") {
       echo "<p>Takk, kommentaren din har blitt sendt.</p>"; 
    } else {
    echo "
    <p> Her kan du sende inn en kommentar til oss om du er fornøyd med servicen. <br /><form action='#' method='get'>
    <label for='name'>Brukernavn: </label>
    <input type='text' id='name' name='user' maxlength='32' size='14' />
    <label for='text'>Kommentar: </label>
    <textarea rows='7' cols='12' maxlength='256'>Skriv her</textarea>
    <input type='submit' value='Send inn' /></form></p>";
   }  ?>

Err. Not really. When I hit Submit nothing happens. It tried to load the page for about 30 sec then it comes an error that says site cannot be shown. New code is:

   <?php
    if (isset($_POST["user"]) and trim($_POST["user"])!="") {
       echo "<p>Takk, kommentaren din har blitt sendt.</p>"; 
    } else {
    echo "
    <p> Her kan du sende inn en kommentar til oss om du er fornøyd med servicen. <br /><form action='#' method='get'>
    <label for='name'>Brukernavn: </label>
    <input type='text' id='name' name='user' maxlength='32' size='14' />
    <label for='text'>Kommentar: </label>
    <textarea rows='7' cols='12' maxlength='256'>Skriv her</textarea>
    <input type='submit' value='Send inn' /></form></p>";
   }  ?>

 

Change form method to "post" instead of "get". Bug is there.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.