开发者

PHP/HTML form submission

开发者 https://www.devze.com 2023-02-21 09:24 出处:网络
I have the HTML and PHP code <form name=\"addaserver\" method=\"post\" action=\"addaserver.php\">

I have the HTML and PHP code

    <form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name<form method="post">
    <input name="servername" type="text" /></form>

    <p>Description<form method="post">
    <input name="description" type="text" /></form>

    <p>Server IP<form method="post">
    <input name="ip" type="text" /></form>

    <p>Tags (ex: &quot;pvp, economy, fun&quot;)<form method="post">
    <input name="tags" type="text" /></form>

    <form method="post">
        <input name="submitserver" type="submit" value="submit" /></form>
    </p>

and (addaserver.php)

$servername=$_POST['servername'];
$desc=$_POST['description'];
$ip=$_POST['ip'];
$tags=$_POST['tags'];

Obviously I'm trying to get the data from the forms...however when I click "submit" it just reloads the开发者_如何学编程 page the forms are on. It's probably just some simple error, but I can't figure out what's wrong D:


You're supposed to define only one form, not one for each input:

<form name="addaserver" method="post" action="addaserver.php">
inputs, inputs, inputs, submit
</form>


First thing I see wrong is that you have two separate form tags in the same HTML.

The second one is pretty much useless as it provides no data to any target or action. I would restructure your HTML to be more like this and try it;

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name<form method="post">
<input name="servername" type="text" /></p>

<p>Description<form method="post">
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: &quot;pvp, economy, fun&quot;)
<input name="tags" type="text" /></p>

<p><input name="submitserver" type="submit" value="submit" /></p>
</form>

Also take note of the fact that I got rid of all your closing form tags as they would have caused issues too. You only need one closing tag at the very outside most segment of your form's body as shown in the code sample too.


You have way too many <form method="post"> tags in your code.

Your code should start with <form method="post"> and end with </form>, but in between there should only be input fields.

You define action to 'addaserver.php' in the first <form> tag, but the submission button is after a different <form> tag so it doesn't respect that initial target you are setting.


You seem to be enclosing all your input element in different tags. a Form tag is a collection of Form elements that will have their values submitted when the form is submitted. And if you do not specify the action attribute on a form it will (as you say) reload the page. So in the above example if you remove all the tags surrounding the input tags and put them all under the same tag you should get your information posted

Look at http://www.w3schools.com/html/html_forms.asp and http://www.tizag.com/phpT/examples/formex.php for examples on how to do this.

Hope that makes sense.


You only need one form tag for the whole form to submit

<form name="addaserver" method="post" action="addaserver.php">
<p>Server Name
<input name="servername" type="text" /></p>

<p>Description
<input name="description" type="text" /></p>

<p>Server IP<form method="post">
<input name="ip" type="text" /></p>

<p>Tags (ex: &quot;pvp, economy, fun&quot;)
   <input name="tags" type="text" />

   <input name="submitserver" type="submit" value="submit" /></form>
</p>


You're nesting extra form tags throughout your form. You only need one form tag. All of the inputs go inside it.

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name</p>
    <input name="servername" type="text" />

    <p>Description<</p>
    <input name="description" type="text" />

    <p>Server IP</p>
    <input name="ip" type="text" />

    <p>Tags (ex: &quot;pvp, economy, fun&quot;)</p>
    <input name="tags" type="text" />

    <input name="submitserver" type="submit" value="submit" />
</form>


Try this instead:

<form name="addaserver" method="post" action="addaserver.php">
    <p>Server Name: <input name="servername" type="text" /></p>
    <p>Description: <input name="description" type="text" /></p>
    <p>Server IP: <input name="ip" type="text" /></p>
    <p>Tags (ex: &quot;pvp, economy, fun&quot;)<input name="tags" type="text" /></p>
    <p><input name="submitserver" type="submit" value="submit" /></p>
</form>
0

精彩评论

暂无评论...
验证码 换一张
取 消