如何避免使用简单的html表单提交重定向?

时间:2017-07-10 20:33:40

标签: javascript php jquery html forms

我为联系页面创建了一个非常简单的html表单。我想知道是否可以禁用/避免在发送表单时发生但仍允许提交表单的页面重定向(显然)。我基本上几乎没有关于php的知识,我没有创建php方面(参见表单操作)。非常感谢任何帮助。

from tkinter import *


root = Tk()

def intro():

  topFrame = Frame(root)
  topFrame.pack()
  bottomFrame = Frame(root)
  bottomFrame.pack(side=BOTTOM)

  photo = PhotoImage(file="hh.gif")
  label = Label(root, image=photo)
  label.image = photo # keep a reference!
  label.pack(side=TOP)

  t = Text(wrap=WORD, height=10)
  t.insert(INSERT, "This is the first screen")
  t.insert(END, "")
  t.pack()

  # button 1 here should take us to the second screen
  button1 = Button(bottomFrame, text="Option 1", fg="black", command=lambda: (t.pack_forget(), label.pack_forget(), button1.pack_forget(), button2.pack_forget(), button3.pack_forget(), chapter2()))
  button2 = Button(bottomFrame, text="Option 2", fg="black")
  button3 = Button(bottomFrame, text="Option 3", fg="black")

  button1.pack(side=LEFT)
  button2.pack(side=LEFT)
  button3.pack(side=LEFT)

def chapter2():

  topFrame = Frame(root)
  topFrame.pack()
  bottomFrame = Frame(root)
  bottomFrame.pack(side=BOTTOM)

  photo1 = PhotoImage(file="hh2.gif")
  label1 = Label(root, image=photo1)
  label.image = photo # keep a reference!
  label1.pack(side=TOP)

  t1 = Text(wrap=WORD)
  t1.insert(INSERT, "This is the second screen")
  t1.insert(END, "")
  t1.pack()

  button4 = Button(bottomFrame, text="this", fg="black")
  button5 = Button(bottomFrame, text="that", fg="black")
  button6 = Button(bottomFrame, text="the other", fg="black")

  button4.pack(side=LEFT)
  button5.pack(side=LEFT)
  button6.pack(side=LEFT)

intro()

root.mainloop()

1 个答案:

答案 0 :(得分:1)

将表单配置为发布到隐藏的iframe,如下所述:How do you post to an iframe?。重定向仍将发生,但它将在iframe内,因此对用户不可见。这有点像黑客,而不是最好的做事方式,但确实有效。