logo
down
shadow

Redirect to URL after form submit in React


Redirect to URL after form submit in React

By : Rohit sharma
Date : November 20 2020, 04:01 AM
I wish did fix the issue. in firebase push() can have a callback function as a second parameter which you can use in your case to check whenever the save process to firebase is done redirect to thank you page.
so after submitting the form and save to firebase, you can redirect to another page like that :
code :
itemsRef.push(item, ()=>{
  window.location.href = "/thankyou.html"; // similar behavior as clicking on a link
});


Share : facebook icon twitter icon
React+redux-form - redirect after submit

React+redux-form - redirect after submit


By : Tim Wu
Date : March 29 2020, 07:55 AM
Hope that helps Create a state variable redirectToNewPage which when true does the redirect. In the callback set redirectToNewPage equal to true.
code :
class LoginForm extends React.Component {
  state = {
    redirectToNewPage: false
  }

  const submit=({email='',password=''})=>{
     ...
     else{

     //redirect to new page
     this.setState({ redirectToNewPage: true })
     }
   }

   render() {

   // The part that makes the redirect happen
   if (this.state.redirectToNewPage) {
     return (
     <Redirect to="/pageAfterSubmit"/>
     )
   }

   return (
     ...
   )  

  }
}
ajax post to laravel can't redirect,form submit can redirect

ajax post to laravel can't redirect,form submit can redirect


By : MyFirstStatsCourse
Date : March 29 2020, 07:55 AM
this will help Instead of returning an redirect to the ajax response, you have to return the url and let the ajax callback function redirect to the url.
So you need to change
code :
return redirect('wx/setdev');
return url('wx/setdev');
$.post("{{route('cfmlogin')}}", {
    _token : "{{csrf_token()}}",
    user : $('#num').val(),
    passwd : $('#passwd').val()
}, function (data) {
    window.location = data;
});
How can I on Submit my Form redirect the Results to another Page in React

How can I on Submit my Form redirect the Results to another Page in React


By : John
Date : March 29 2020, 07:55 AM
wish helps you After receiving your api calls you can throw a push and move to another page. For yours it may look something like this.
code :
    getTrend = async (e) => {
    e.preventDefault();

    const keyword = e.target.elements.keyword.value;

    const api_call = await fetch(`http://localhost:8081/trend/twitter?keyword=${keyword}`); //make API call

    const data = await api_call.json(); 


   if (keyword) {
        this.setState({
          tweets: data
        });
        console.log(this.state.tweets);
        this.props.history.push({
  pathname: '/results',
  state: { detail: data }
})
      } 
      else {
        this.setState({
          tweets: undefined,
          error: "Please enter the values"
        });
      }
  }
props.location.state.detail
How can i redirect after submit form React

How can i redirect after submit form React


By : user3381944
Date : March 29 2020, 07:55 AM
wish of those help fetch can be used with either callbacks or promises, you need to wait for the asynchronous request to finish before you redirect.
This is a simply callback example, it assumes you do not need to access the response body of the request or need to check the response status.
code :
function Test() {
  const { register, handleSubmit } = useForm()
  const onSubmit = data => {
    fetch(`http://localhost:4000/signup`)
      .then(resp => {
        // Navigate here, either:
        // use browser (not nice if SPA)
        window.location = "http://www.url.com/path";
        // use connected react router
        // implementation specific
        // e.g. this.props.push("/path");
      });
  }
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      ....
    </form>
  );
}
function Test() {
  const { register, handleSubmit } = useForm()
  const onSubmit = async (data) => {
    await fetch(`http://localhost:4000/signup`);
    // navigate here
  }
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      ....
    </form>
  );
}
Redirect from browser form submit button to app react native

Redirect from browser form submit button to app react native


By : Allen Michaels
Date : March 29 2020, 07:55 AM
This might help you This all you can do it in on navigation state change so when you submit from that will return an response and that response you can capture and on that condition you can navigate to another screen.
i my scenario i am using for payment with instamojo.
code :
import React, { Component } from "react";
import { Text, View, StyleSheet, WebView } from "react-native";
import { BASE_URL } from "../../../constants/apiList";
import SecondaryHeader from "../../common/SecondaryHeader";

class Payment extends Component {
  constructor(props) {
    super(props);

    this.state = {
      isLoading: true,
      refreshing: false,
      isPiad: false,
      packages: []
    };
  }
  getParameterByName(name, url) {
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
      results = regex.exec(url);
    if (!results) {
      return null;
    }
    if (!results[2]) {
      return "";
    }
    return decodeURIComponent(results[2].replace(/\+/g, " "));
  }
  onNavigationStateChange = eve => {
    if (eve.loading !== this.state.isLoading) {
      this.setState({
        isLoading: eve.loading
      });
    }
    if (eve.url.indexOf("api/orders/") > -1) {
      this.props.navigation.replace("paymentStatus", {
        url: eve.url,
        id: this.props.navigation.state.params.id
      });
    }
  };
  render() {
    return (
      <View style={styles.container}>
        <SecondaryHeader title="PAYMENT" {...this.props} />
        <WebView
          source={{ uri: this.props.navigation.state.params.url }}
          onNavigationStateChange={this.onNavigationStateChange}
          style={{ height: 200 }}
          startInLoadingState={true}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1
  }
});

export default Payment;
Related Posts Related Posts :
  • dropdown flexibility?
  • How "d3.translateExtent" coordinate works?
  • Get the element of an array that has an index given by a variable in JavaScript
  • Replace(), replacing a value not specified
  • javascript native equivalent to .each & .attr
  • Fabric getPointer method not working in Firefox
  • JS scripts not working for divs loaded with jQuery's .load()
  • Use xhr code error on switch/case (javascript)
  • ParseFloat return string instead of number in Javascript
  • How to add a custom script into React app component?
  • Show data while it's being sent to the backend
  • selecting a specific class with .parents()?
  • Get value of a selected option in an label with Javascript
  • How Do I get an HOC wrapped component function from enzyme instance when mounting?
  • i want to update the flashdata on every ajax call
  • Cannot find a tag with JSsoup even though the tag exists in Node JS
  • Exporting the RouterModule?
  • Remove the default checked value in radio button and replace it with the another radio button that is click
  • Switch to test for id and perform action based on class
  • JavaScript Random Number Generation: Unique 500 Integers in Space 10^6: Getting Collisions
  • Display files in directory using PHP and jQuery
  • Knockout JS: adding forms in foreach bindings
  • HTML5 Canvas positioning mouse clicking broken
  • JQuery on change fired only after second change of select box
  • Unable to limit WebRTC P2P Multi-participant Receiving Bandwidth
  • What is the RegEx to just return the last part of the URL
  • State Remains Undefined in React
  • removing content on website before a screen reader can read it with either JavaScript or CSS...?
  • on 'click' firing before click
  • Manipulation of an array sent by ajax to a php file, within a function of another file
  • How to use plunker or jsfiddle to run angular2 code
  • JavaScript lexical environments as objects
  • Iteratively position spheres with DOM pixels using three.js and React
  • React trying to access file at a wrong path
  • AES encryption in JS equivalent of C#
  • Filter an Array based off user input string and menu dropdown items
  • Constantly read local file with JS?
  • React navbar handler with theme
  • Show changes to HTML5 canvas immediately
  • Tooltip Stays Hidden In D3 Treemap
  • Backbone - What is the best way to listen to 2 models?
  • formatting an array of objects output
  • Bind input value to specific value in object
  • Animation doesnt work when onClick event occurs (react.js)
  • Consume enum from ambient TypeScript module using @babel/preset-typescript?
  • Changing order of React components only triggers re-render after second click
  • Track the total time the HTMLAudio was playing
  • Call javascript function in PHP file and load html file after?
  • Theme Development: JavaScript not working when linked from functions.php
  • Add attributes to multiple <td> in datatables
  • Progressive loading codesnip not quite understood
  • How to format default date in javascript?
  • Caesar cipher only gets first value right
  • innerText not showing after setting it straight after creating the element
  • How to use HTML template tag with jQuery?
  • Showing v-menue's selected option in another part of the application. Vuetify
  • How can I find and return my div element with rails and javascript?
  • The right way to use Ajax to Update a Single field in a specific Object
  • Hhow to create a react element and apply a javascript method to it
  • Change src of parent window iframe
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org