Polymer + form POST data

六月ゝ 毕业季﹏ 提交于 2019-12-18 12:53:13

问题


I have this

<form id="form_837299" class="appnitro"  method="post" action="insert.php"> <paper-input label="Title" name="title" maxlength="255">
            </paper-input>
          <paper-input floatinglabel multiline label="text" name="text"></paper-input>                           


          <li class="buttons">                                       

            <input type="hidden" name="form_id" value="837299" />                                                        
            <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />                           
          </li>                          
        </ul>                    
      </form>

I have problem with POST data - nothing is sended in "text" and "title" (all in paper-input).

I modified the template and attribute "name" now is in one div, which Polymer created. But no data are sent.

print_r($_POST); shows me only this: Array ( [form_id] => 837299 [submit] => Submit )

Anybody knows how use Polymer and Material UI on form?


回答1:


Only elements that extend native form elements automatically get submitted with forms. paper-input extends core-input which has an input inside it as opposed to extending it. See this mailing list discussion for additional discussion and this StackOverflow post for possible solutions.

Something like this jsbin maybe?

Update: Here's the same thing in web component form.

Update: Looks like the creator of ajax-form has added this functionality.

Update: Also consider using iron-form.




回答2:


According to the Polymer docs the way to do this is to just create a regular form input and wrap it in the <paper-input-decorator>

https://www.polymer-project.org/docs/elements/paper-elements.html#paper-input

I've tried it out and it works fine. Some better form support would be cool, but oh well. This stuff still kind of rocks.

UPDATE: I've built a bower package (polymer-rails-forms) to deal with forms in polymer, tailored specifically to the ActiveRecord input naming scheme but it will work with any old form really. It's still relatively new, but it covers most input types, basic validations, xhr and non-xhr submits and has a couple cool extras like image, json, and location* fields.

the location fields depend on the Google Map Places API



来源:https://stackoverflow.com/questions/24461460/polymer-form-post-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!