Using same php file to show form and receive the form's data

前端 未结 3 662
时光取名叫无心
时光取名叫无心 2021-01-23 17:00

I have a php page that generates a form. The action attribute of the form is the page itself. After the user submits the form, the same page is loaded, but this time a POST vari

相关标签:
3条回答
  • 2021-01-23 17:07

    The bad part is setting the action attribute to the script. Omitting it completely indicates to the browser that it should be posted to the same URL.

    0 讨论(0)
  • 2021-01-23 17:14

    I agree with Ignacio. Other than that it looks like a fairly standard approach if you don't need more complexity. One very important thing: make sure you are validating and sanitizing that data before it goes into the database.

    0 讨论(0)
  • 2021-01-23 17:21

    You might even want to go to the extent of checking whether the data was submitted thru AJAX to differentiate it from a regular form submission:

    if ( $_SERVER['X_REQUESTED_WITH']=='XMLHttpRequest' )
      // AJAX
    
    0 讨论(0)
提交回复
热议问题