Jump to content

question on page submissions


graham23s

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.