Determine if form submission was successful #20
              
                Unanswered
              
          
                  
                    
                      lewebsimple
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 1 comment
-
| You can define your submission logic in the onSubmit function. This logic may include asynchronous operations, such as sending data to a server. After the asynchronous operation resolves, you can then display a success message. Here's an example code snippet using Vorms: <script setup lang="ts">
import { useForm } from '@vorms/core'
const { handleSubmit } = useForm({
  initialValues: {
    drink: '',
    sugar: 'light',
  },
  onSubmit(data) {
    return submit(data).then((response) => {
      console.log('success!!')
      // Add your success message display logic here
    })
  }
})
async function submit(data) {
  const response = await fetch('/api/submit-form', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(data),
  });
  return response.json();
}
</script>
 | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
When the form is submitted successfully, we usually want to display a success message instead of the form itself.
I'm not sure how to achieve this with the current API without handling that logic myself.
Am I missing something ?
Beta Was this translation helpful? Give feedback.
All reactions