stefsoko Posted January 15, 2011 Share Posted January 15, 2011 I currently have a small 2 page message board, the main file is named index.php and the other core.php - I would like to rename the main file with the form to chat.php, but when I do that, the script no longer posts messages, and goes to the website root. Can someone tell me whats wrong? Here is the form info from the current index.php (that i wish to rename chat.php) <form action="./" method="post"> <p>name (25 chars max)<br> <input id="name" name="author" maxlength="20" size="25"></p> <p>message (150 chars max)<br> <input id="message" name="message" maxlength="150" size="45"></p> <p>what is <?php echo "$num1 + $num2?" ?><br> <input id="captcha" name="captcha" maxlength="2" size="10"></p> <p><input id="submit" name="submit" type="submit" value="submit"> (ip addresses are recorded)</p> </form> and the 2nd file core.php's function that I think is acting up (here or with the form above?) function getPosts() { $author = isset($_POST['author']) ? $_POST['author'] : false; $message = isset($_POST['message']) ? $_POST['message'] : false; global $nameMax; global $messageMax; global $error; if ($author && $message && ($error==false) ) { if (strlen($author) <= $nameMax && strlen($message) <= $messageMax) { $this->inputPost($author, $message); header('Location: ./'); } Why when I rename index.php to chat.php is it not working and falling back to the website root when I submit? any help would be great! I am sure it is something simple, but I am new... Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/ Share on other sites More sharing options...
mikosiko Posted January 15, 2011 Share Posted January 15, 2011 if you rename your index.php file this 2 lines must be modified accordingly <form action="./" method="post"> and header('Location: ./') Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/#findComment-1159962 Share on other sites More sharing options...
stefsoko Posted January 15, 2011 Author Share Posted January 15, 2011 would it be ... <form action="core.php" method="post"> and header('Location: chat.php') ????? Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/#findComment-1159973 Share on other sites More sharing options...
mckgr Posted January 15, 2011 Share Posted January 15, 2011 The action element needs to be changed to reflect the new filename. So you would want to set it to chat.php... A more general solution, since this page is submitting to itself, would be to just use action="", causing it to submit to itself, arguements and all (were there any set). Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/#findComment-1159976 Share on other sites More sharing options...
stefsoko Posted January 15, 2011 Author Share Posted January 15, 2011 The action element needs to be changed to reflect the new filename. So you would want to set it to chat.php... A more general solution, since this page is submitting to itself, would be to just use action="", causing it to submit to itself, arguements and all (were there any set). so i change the chat.php form action to this... <form action="" method="post"> or <form action="chat.php" method="post"> but what about this line in the core.php file...? header('Location: ./') Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/#findComment-1159987 Share on other sites More sharing options...
mckgr Posted January 15, 2011 Share Posted January 15, 2011 Ah yea. That would need to be set to chat.php I think. Link to comment https://forums.phpfreaks.com/topic/224557-whats-wrong-with-my-form-when-i-rename-my-files/#findComment-1159989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.