submit form

Have submit form at bottom of webpage.html. Want page to refresh and user input appear under submit form.

Webpage
[php]

body{font-family:arial; } table{font-size:100%;background:} a{color:#000000;text-decoration:none;font:bold} a:hover{color:#000000} td.menu{background:} table.menu { font-size:100%; position:absolute; visibility:hidden; }

Another Year



Share Your Thoughts

       Name:

       Email:

   Website:

Comments:

Comments:

<?php include "comments.html" ?>
    <a href="http://kbizopps.com/" target="_blank"><font color="#000000">Home</font></a> &#124;
    <a href="about.html"  target="_blank"><font color="#000000">About</font></a> &#124;
    <a href="mailto:[email protected]" target="_blank"><font color="#000000">Contact</font></a></h5></center>
[/php]

index.php
[php]<?php
if(isset($_POST[‘submit’])) { // Added not to display “please fill out all reqired fields”.
$name = htmlentities($_POST[‘name’]);
$email = htmlentities($_POST[‘email’]);
$website = htmlentities($_POST[‘website’]);
$message = htmlentities($_POST[‘message’]);
$time = time();
@ $fp = fopen(‘comments.html’,‘a’);
if (!$name || !$email|| !$website || !$message )
{
echo “Please fill out all required fields”;}
else
{
if(strlen($name) > 0 && strlen($message)> 0) {
if(filesize(‘comments.html’) >= 0) {
$pre =’
’;
}
}

$outputstring = $pre. ‘

’.$name.’. ‘.date(‘F j Y \a\t h:i a’,$time).’

'.$message .'

'; @fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp);

echo “”; // changed from Header( )
}
}

?>

       Name:

       Email:

   Website:

Comments:

Comments:

<?php include "comments.html" ?>

[/php]

Are you asking for the user to fill out the form and on submit have it go to a page to check values and then redirect back to the original page to output the values? I’m not sure what your really asking. Could you please clarify and be specific in what you are asking?

Yes. After users fill out form and submit, I want input to appear at the bottom of webpage under the form, instead of redirecting.

That’s very easy. Instead of doing .html make it .php and then do this with the code you provided…

[php]

body {font-family:arial;} table{font-size:100%;background:} a{color:#000000;text-decoration:none;font:bold} a:hover{color:#000000} td.menu{background:} table.menu { font-size:100%; position:absolute; visibility:hidden; } /style> script type="text/javascript"> function showmenu(elmnt) { document.getElementById(elmnt).style.visibility="visible"; } function hidemenu(elmnt) { document.getElementById(elmnt).style.visibility="hidden"; }

Another Year



Share Your Thoughts

       Name:

       Email:

   Website:

Comments:

<?php if(isset($_POST['submit'])) { // Added not to display "please fill out all reqired fields". $name = htmlentities($_POST['name']); $email = htmlentities($_POST['email']); $website = htmlentities($_POST['website']); $message = htmlentities($_POST['message']); $time = time(); @$fp = fopen('comments.html','a'); if(!$name || !$email|| !$website || !$message ) { echo "Please fill out all required fields"; } else { if(strlen($name) > 0 && strlen($message)> 0) { if(filesize('comments.html') >= 0) { $pre ='
'; } } $outputstring = $pre. '

'.$name.'. '.date('F j Y \a\t h:i a',$time).'

'.$message .'

'; @fwrite($fp, $outputstring, strlen($outputstring)); fclose($fp); echo ""; // changed from Header( ) } } ?>

       Name:

       Email:

   Website:

Comments:

Comments:

<?php include "comments.html" ?>

Comments:

<?php include "comments.html" ?>

Home &#124;
About &#124;
Contact

[/php]

To be clear, are you saying change webpage from .html to .php?

Yes. If “Webpage.html” is the name of your html file then change it to the “Webpage.php” and you can do your php directly in that page instead of sending it elsewhere.

Was saying webpage as example. The name of html file is another-year. Change it another-year.php?

yes

Tried it in php. Input disappeared after clicking submit and switched to .html.

change form action to ‘another-year.php’

[php] [/php]

Changed form action. Works on localhost, but when I try it on server, input stil disappears after submit.

Did you make sure to upload all files that you may have changed? It seems like a bad question but I know I have spent a stupid amount of time troubleshooting my scripts because of silly things like that.

1 Take the form action out, you’re redirecting to that page, not using it to process php.
2 move the php to the top of the page
3 change the metatag back to header() - header('Location: webpage.php");
4 close your table rows

<< you’re missing on all of them
5 is depreciated and not supported in some browsers, I suggest learning css
6 need to put your form tab before the table.

Yes. Uploaded webpage including index.php and that’s it. Unless I left something out.

Not necessary. It works. Just trying to get it to work on server.

You should really listen to what richei said as he is absolutely correct. He gave you nothing but good advice. You should fix your code using richei’s suggestions and then show us the scripts you are using including the filename for each.

If it worked, you wouldn’t be here asking why it doesn’t work :slight_smile:

I said it works on localhost, but not on server.

Followed instructions and ended up with errors. Code was fine, before.

Can you show us the code that you have now?

Sponsor our Newsletter | Privacy Policy | Terms of Service