Question

As the title, I got some problem when trying to use button elements in a form, exactly is MyBB forms.

For example, we want to create a new thread right?

So we have these :

  • newthread.php (MyBB root)
  • newthread template (inside MyBB admincp)

The form will look like this

<form action="newthread.php?tid=XX">
...
<button type="submit" name="submit">Post Thread</button>
<button type="submit" name="previewpost">Preview Post</button>
...
</form>

And you will know what will happen next, when we click to the Preview Post button, it will submit the form. I change the type="submit" => type="button" but I don't know how to make the form know that I want to preview the post.

Any help for this?

Was it helpful?

Solution

Well,

I believe all you need to do is specific value for your buttons:

<form action="newthread.php?tid=XX">
...
<button type="button" value="submit" name="submit">Post Thread</button>
<button type="button" value="previewpost" name="previewpost">Preview Post</button>
...
</form>

Then you can start using your existing javascript code to handle the AJAX.

OTHER TIPS

If you are using jQuery:

$('button[name="previewpost"]').click(function () {
    /* do something */
});

If you are using native JS:

function clickFunction() {
    /* do something */
}
document.getElementsByName('previewpost').onclick(clickFunction);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top