Emaziz Posted June 1, 2009 Share Posted June 1, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/ Share on other sites More sharing options...
sc_84 Posted June 1, 2009 Share Posted June 1, 2009 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846951 Share on other sites More sharing options...
Emaziz Posted June 1, 2009 Author Share Posted June 1, 2009 Thanks. It makes no difference though. Even though user does not equal to "" (which is blank?) the form still shows. Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846962 Share on other sites More sharing options...
anupamsaha Posted June 1, 2009 Share Posted June 1, 2009 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? Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846967 Share on other sites More sharing options...
Emaziz Posted June 1, 2009 Author Share Posted June 1, 2009 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846971 Share on other sites More sharing options...
anupamsaha Posted June 1, 2009 Share Posted June 1, 2009 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. Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846972 Share on other sites More sharing options...
Emaziz Posted June 1, 2009 Author Share Posted June 1, 2009 Edit: Wait 2 sec.. Misread Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846973 Share on other sites More sharing options...
anupamsaha Posted June 1, 2009 Share Posted June 1, 2009 Edit: Wait 2 sec.. Misread If you want to keep the form action as "get", use $_GET instead of $_POST. If you change form action to "post", use $_POST. Thanks. Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846974 Share on other sites More sharing options...
Emaziz Posted June 1, 2009 Author Share Posted June 1, 2009 Al'right. It works. Huzzah! Thanks alot guys. I changed method to 'post'. Problem solved! Link to comment https://forums.phpfreaks.com/topic/160493-solved-noob-needs-help-with-refresh-on-click-and-change-text-thingy-d/#findComment-846975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.