Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html form posting, no data passed on [duplicate]

Tags:

html

post

forms

php

I've been sitting with this problem for a while now, can't seem to figure out whats wrong with the code.

The problem is that no data gets posted from the form to the script.

<div class="mws-panel-body">
    <form class="mws-form" action="blueprints/add" method="post" id="pForm">
        <div class="mws-form-inline">
            <div class="mws-form-row">
                <label>Blueprint name</label>
                <div class="mws-form-item small">
                    <input type="text" class="mws-autocomplete mws-textinput" id="pName" value="" />
                    <div>The name of the blueprint, search completion is enabled.</div>
                </div>
            </div>
            <div class="mws-form-row">
                <label>Hangar</label>
                <div class="mws-form-item micro">
                    <select id="pHangar">
                        <option value="0" selected>Personal</option>
                        <option value="1">Corporation</option>
                    </select>
                    <div>Indicates who the blueprint belongs to.</div>
                </div>
            </div>
            <div class="mws-form-row">
                <label>State</label>
                <div class="mws-form-item micro">
                    <select id="pState">
                        <option value="1" selected>Original</option>
                        <option value="0">Copy</option>
                    </select>
                    <div>The state of the blueprint, be it original or a copy.</div>
                </div>
            </div>
            <div class="mws-form-row">
                <label>Productions runs</label>
                <div class="mws-form-item small">
                    <input type="text" class="mws-textinput" id="pRuns" value="0" />
                    <div>The number of production runs left on copy.</div>
                </div>
            </div>
            <div class="mws-form-row">
                <label>Material efficiency</label>
                <div class="mws-form-item small">
                    <input type="text" class="mws-textinput" id="pME" value="0" />
                    <div>The current material efficiency level of the blueprint.</div>
                </div>
            </div>
            <div class="mws-form-row">
                <label>Production efficiency</label>
                <div class="mws-form-item small">
                    <input type="text" class="mws-textinput" id="pPE" value="0" />
                    <div>The current production efficiency level of the blueprint.</div>
                </div>
            </div>
        </div>
        <div class="mws-button-row">
            <input type="submit" value="Add blueprint" class="mws-button blue" />
            <input type="reset" value="Reset" class="mws-button gray" />
        </div>
    </form>
</div>

It seems to be a problem with the form itself, as if the form is set to get, it just enters the script with a question-mark only, blueprints/add?, meaning no data gets passed on at all.

Any pointers or suggestions will be appreciated.

My platform is PHP if that helps.

like image 239
SorenA Avatar asked Dec 08 '25 17:12

SorenA


2 Answers

You should be using the name attribute of input to send the data to a PHP post script. Example:

Form:

<form action="add.php" method="post">
    <input type="text" name="firstname" />
</form>

Script (add.php):

<?php
//print the $_POST['firstname'] variable
echo $_POST['firstname'];
?>
like image 90
Cameron Avatar answered Dec 10 '25 10:12

Cameron


You need to add the name attribute to your input and select elements

<input type="text" name="myinput">

Php will then build your $_POST array with those names.

like image 40
shapeshifter Avatar answered Dec 10 '25 09:12

shapeshifter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!