Sending form with POST method and Polymer iron-for

2019-05-15 14:39发布

i use Polymer starter kit 1.0.2 and i'm trying to use iron-form based on (little) documentation i found.

My method form is "post" and contain only one input.

My form "action" is a PHP script (add.php) showing content of $_GET and $_POST:

print_r($_POST);
print_r($_GET);

My form component (form_eclp.html) is:

<dom-module id="my-form">
    <template>
        <div class="horizontal center-center layout">
            <div>
                <div class="horizontal-section">
                    <form is="iron-form" id="formGet" method="post" action="add.php">
                        <paper-input name="name" label="Name" required></paper-input>
                        <br><br><br>
                        <paper-button raised onclick="clickHandler(event)">Submit</paper-button>
                    </form>
                </div>
            </div>
        </div>
    </template>
    <script>

        function clickHandler(event) {
            Polymer.dom(event).localTarget.parentElement.submit();
        }

        Polymer({
            is: 'my-form',
            listeners: {
                'iron-form-response': 'formResponse'
            },
            formResponse: function(e) {
                // ?????????
            }
        });
    </script>
</dom-module>

I call if from:

<link rel="import" href="form_eclp.html">
<my-form></my-form>

When i click the submit button after entering the text 'test' in name input, i can see in the network tab of the browser developper tools that it's a POST request, ok, but the url is add.php?name=test, and in the response tab i have:

Array
(
)
Array
(
    [name] => test
)

According to my form action (add.php script), first array is for $_POST and the second $_GET.

I can see, despite form method="post", it's a "get" request because only $_GET is populated, there is nothing in $_POST.

I don't understand, is it a bug ?

2条回答
Ridiculous、
2楼-- · 2019-05-15 15:27

This isn't an answer but as I can't comment I will have to ask this here. Have you had tried putting anything in a database using the iron-form? I have been trying to get data into a db from a few $_POST's and haven't had any luck with it.

查看更多
太酷不给撩
3楼-- · 2019-05-15 15:40

So it seems like the form-input is outdated in your bower.json. Do this: bower install -S PolymerElements/iron-form and everything should be fine.

查看更多
登录 后发表回答