开发者

How to add a post parameter to manual form submission?

开发者 https://www.devze.com 2023-04-12 22:21 出处:网络
I want to submit a form manually after some complicated checks. Because checks involve user interaction, the whole check process is not done synchronously. Here is the scenario:

I want to submit a form manually after some complicated checks. Because checks involve user interaction, the whole check process is not done synchronously. Here is the scenario:

  1. User clicks a button (an HTML <button id='button-id'> tag)
  2. I prevent the default action of the button (which is the form submission)
  3. I do a complicated check.
  4. Somewhere in the check process, I show a dialog and wait for the user to respond (here, the original check function proceeds and returns)
  5. I provide a callback function for that dialog, wh开发者_Python百科ich fires and runs when the user closes it (either positive or negative result)
  6. Now, I should submit the form, but the original HTML <button id='button-id'> should be posted as a successful control. In other words, I should add the name of the button tag as one of the posted parameters to the server.

I use jQuery's $('#form-id').submit() method. How can I add the name of the <button> element to the HTTP Post parameters?


You could append a hidden field to your form before submitting -

$('<input>').attr({
    type: 'hidden',
    id: 'buttonid',
    name: 'buttonid',
    value: yourbuttonidvar  
}).appendTo('#form-id');


Instead of using a button type, why not use

<input type="submit" name="commit" id="button_id" ...>
0

精彩评论

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