Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to POST form to server #152

Closed
prattcmp opened this issue Jun 27, 2015 · 14 comments
Closed

No way to POST form to server #152

prattcmp opened this issue Jun 27, 2015 · 14 comments
Labels

Comments

@prattcmp
Copy link

It amazes me that there is no built in way to submit the form to the server. I don't want to do $.post. I want an action with a URL and a POST method. I've tried setting those attributes in <Formsy.Form> and programmatically to no avail. None of the examples even show what happens after you click submit. Nobody alerts with a JSON string after submitting a form! Any way to submit a form normally so I can use my server side validation and routing?

@Semigradsky
Copy link
Collaborator

You can use your favorite library for this. Superagent for example:

var request = require('superagent');
...
var Login = React.createClass({
  ...
  submit: function (data) {
    request.post('/app/login', data).end(function (err, res) {
      // do smth
    });
  },
  ...
  render: function () {
    return (
      <Formsy.Form onValidSubmit={this.submit}>
        ...

@prattcmp
Copy link
Author

I don't want to do client-side requests. I want to use HTTP POST. Method="post" action="mypage.php"

Thanks for setting the label. I couldn't do it on my phone.

@Semigradsky
Copy link
Collaborator

I'm sorry, I can't quite understand why not make http post requests from the script.

@prattcmp
Copy link
Author

Because then I have to handle errors and routing clientside. That would make a huge mess in my code.

@prattcmp
Copy link
Author

I believe that this feature does not exist, so this is less of a question and more of a request.

@ericdfields
Copy link

I can't quite tell what you're going for either. Do you want to perform client-side validation and then, if the validations are all good, perform a standard POST?

@prattcmp
Copy link
Author

Yes.

@ericdfields
Copy link

You could use any of the validation-related methods described in the API to achieve your goal, depending on the behavior you're looking for.

The example in the Readme will, for example, disable the submit button until the form is valid. Upon submitting the form, it will do a standard POST.

@prattcmp
Copy link
Author

It does not do a standard POST. It triggers a submit method that has some unknown function. There is also no way to set an action or a method AFAIK.

@ericdfields
Copy link

My apologies. You’re correct and it does expect you to handle POST your own way. Here is the function: https://github.com/christianalfoni/formsy-react/blob/master/src/main.js#L81-L94 https://github.com/christianalfoni/formsy-react/blob/master/src/main.js#L81-L94

I don’t think you can pull of what you want to then. Just might not be the library you’re looking for.

On Jun 29, 2015, at 12:19 PM, vinylrain [email protected] wrote:

It does not do a standard POST. It triggers a submit method that has some unknown function. There is also no way to set an action or a method AFAIK.


Reply to this email directly or view it on GitHub #152 (comment).

@prattcmp
Copy link
Author

Yeah, this is more of a feature request than a question now.

@Checksum
Copy link

+1 to this. I'm using formsy mainly to maintain state for a complex form, including custom validations. Works well for that. What I would then like to do is trigger a normal HTTP post by passing the action and method parameter.

If this is something that will be considered, I can send a pull request.

@christianalfoni
Copy link
Owner

Hi there,

Formsy is built for flexibility. There are so many different ways of handling a form and to support most of them Formsy has a lot of hooks. Initially Formsy did support posting data directly to the server and handle any errors, but the implementation was too specific. There were so many requests on support of headers, map errors from server etc. It just got way out of control. So instead of having one very opinionated implementation of talking to the server, it has an extremely flexible hook that lets you do it exactly as you want to.

So I am sorry to say that this will not be implemented... and I can not really see that this is a problem?:

sendData(form, reset, invalidate) {
  myAjaxLib.post('/form', form)
    .success(this.doWhatever)
    .error(invalidate);
},
render() {
  return <Formsy.Form onSubmit={this.sendData}/>
}

Sorry to be such a dick about it ;-)

@Nopik
Copy link

Nopik commented Apr 14, 2017

I also can't believe that Formsy doesn't have this out of the box. Thats literally a book example of what <form> is for. And explaination that it does so, because of flexibility is really astounding.. as Formsy out of the box is not flexible enough to support using the existing mechanisms (and e.g. getting html response from submit, or handle target property of <form>).

Anyway, I added #441 to add support for standard submit. @christianalfoni: any chances to get this merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants