1

I have a ReactJS form that I should send to a PHP page, but for some reason when I submit the form the page goes to http://localhost:3000/ricevi.php?input21=a&input2_=b and the page refreshes not executing the PHP code.

This is the code I made:

<form className="formoid-solid-red" action="ricevi.php" method="GET">
    <!-- inputs --->
    <input type="submit" value={this.state.can_send_btn} disabled={this.state.can_send}/>
</form>

Note: I'm using the create-react-app and yarn start to make my app run.

Mr.Web
  • 6,992
  • 8
  • 51
  • 86

1 Answers1

1

Couple of things to note:

You are not handling the form submission through react so this question may not be related to react... in case you are attempting to do so, you should attach an event listener to your form, so it handles the submit and then you can create a request to your server from within the component.

You can find some examples in react documentation https://reactjs.org/docs/forms.html#controlled-components

In this case you should remove the action and method attributes from your from element.

If you are not looking to do that then you need to debug your server and figure it out — does your server executes the expected code when you enter that url directly, etc...

jenriquer
  • 166
  • 2