Sending form with POST method and Polymer iron-form?
Asked Answered
B

2

3

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 ?

Boothman answered 29/6, 2015 at 16:54 Comment(0)
K
1

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.

Karoline answered 2/7, 2015 at 13:58 Comment(2)
Thanks. You saved me countless hours of research! Been messing with it for too long. I did do bower update. Does that not do the same thing?Twi
@Boothman - You actually managed to get iron-form to work? Please don't keep us in the dark, what did you add in place of the // ?????????Hyman
S
0

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.

Striking answered 7/7, 2015 at 1:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.