graham23s Posted December 12, 2007 Share Posted December 12, 2007 Hi Guys, im making a basic forum and one of the pages submits to itself code: <?php ## submission if(isset($_POST['submit'])) { ## the vars $var_topicname = clean($_POST['subject'],1); $var_topicbody = clean($_POST['body'],1); $var_mainforumid = mysql_real_escape_string($_POST['hid1']); ## error checking if(empty($var_topicname)) { stderr("Error","You left the topic name empty!"); include("includes/footer.php"); exit; } if(empty($var_topicbody)) { stderr("Error","You left the topic body empty!"); include("includes/footer.php"); exit; } } ## $_GETs $mainforumid = $_GET['mainforumid']; ## html form echo ("<form action=\"\" method=\"POST\" />"); echo ("<table class=\"sub_table\" align=\"center\" width=\"60%\" border=\"1\" bordercolor=\"#000000\" cellpadding=\"5\" cellspacing=\"0\">"); echo ("<tr>"); echo ("<td colspan=\"2\" class=\"header_boxes\" align=\"left\"><span class=\"prof_head\">Post a New Thread - [$mainforumid]</span></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"right\"><b>Subject</b></td><td align=\"left\"><input type=\"text\" name=\"subject\" size=\"40\"></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"right\" valign=\"top\"><b>Body</b></td><td align=\"left\"><textarea name=\"body\" rows=\"20\" cols=\"80\"></textarea></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td colspan=\"2\" align=\"right\" valign=\"top\"><input type=\"hidden\" name=\"hid1\" value=\"$mainforumid\"><input type=\"submit\" class=\"btn\" name=\"submit\" value=\"Post Topic\"></td>"); echo ("</tr>"); echo ("</table></form>"); ?> everything works ok but the url is like this: http://www.site.com/newthread.php?mainforumid=1&posterid=9 im wondering if my form action ("<form action=\"\" should have all the extra id's and things in it ?mainforumid=1&posterid=9 like that when i submit it? just curious as to the proper ways to do things thanks guys Graham Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted December 12, 2007 Share Posted December 12, 2007 If the action is empty, then it will submit to the current page. The action attribute cannot be empty or missing in XHTML 1.0 Strict though, I'm not sure about transitional. And just for making your code cleaner, you might want to do either "<form action='' method='POST' />" or '<form action="" method="POST" />' so you won't have to escape all those characters. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.