开发者

How do I include and submit a form using Impromptu dialog

What is the proper way to include and submit a form to a PHP page via开发者_高级运维 jquery impromptu.

Currently, I'm doing:

<script>
  var someform = '<form method="post" action="my.php" id="myform">
  Enter your name<br />
  <input name="name" /><br />
  What's your favorite color?<br />
  <select name="color">
    <option>red></option>
    <option>blue</option>
  </select><br />
  Tell us more about that<br />
  <textarea name="comments"></textarea>
  <input type="hidden" name="submit" />
  </form>';

  function callback_form(v,m,f){

    if(v == 1)
    {
  $('#myform').submit();
      location.reload();
    }
    else
    {
      $.prompt.close()
    }
  }
</script>

In the html, when I call it, the form displays and refreshes the page, but doesn't submit.

<a href="#" onclick="$.prompt(someform,{ callback: callback_form, buttons: { Cancel: 0, Add: 1 },focus: 1 });">Launch Form</a>

I feel like there's gotta be some easy mistake I'm making, but I can't find any examples of someone actually including form tags using impromptu. I'm hoping someone can point me in the right direction. Can anyone help me with the best method of prompting for user input and actually submitting the form using impromptu?


That is, beause you are reloading the page while you are submiting. If you submit the form, your page will go to the 'my.php', so you do not need the 'location.reload()'.


You should be able to submit the form via ajax like this:

$.post('my.php',f,function(data,status,xhr){
    //do something here
});


I figured it out; thanks for the help!

Apparently, I needed to change callback to submit

$.prompt(someform,{ callback: callback_form

to $.prompt(someform,{ submit: callback_form ). When I referenced the submission behavior instead of calling the function, everything worked just as it should.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜