PHP表单在bootbox中

时间:2017-07-12 16:36:42

标签: javascript php forms bootbox

我是PHP和Javascript的新手,有一些问题,如果有人可以帮助我。 我在启动箱中有这个PHP表单,因为它在图像中: Image of the bootbox

代码:

function dialogUpload() {
    bootbox.confirm({
        message:  '<form action="../Control/upload.php" method="post" enctype="multipart/form-data"> '
                + '     Nome do objeto:<br />'
                + '     <input name="objectname" type="text"><br />'
                + '     Objeto 3D(Formato <b>.dae</b>):<br />'
                + '     <input name="userfile[]" type="file" /><br />'
                + '     Imagem 2D do objeto(Formato <b>.png</b> ou <b>.jpg</b>) (<i>Opcional</i>):'
                + '     <input name="userfile[]" type="file" /><br />'
                + '     Comentário:<br />'
                + '     <textarea name="comment" rows="5" cols="75"></textarea>'
                //+ '   <input type="submit" value="Send files" />'
                + '</form>',
        buttons: {
            confirm: {
                label: 'Enviar Arquivo',
                className: 'btn-success'
            },
            cancel: {
                label: 'Cancelar',
                className: 'btn-danger'
            }
        },
        callback: function (result) {
            if(result){

            }
        }
    });

我想对这种形式做些什么:

  • 使用“EnviarBotão”按钮提交表单(如何在回调中执行此操作?)
  • 验证文件格式是否为有效格式(1º中的.dae和2º中的.png或.jpg),如果格式不是有效格式(显示错误消息),则将其阻止。
  • 使第二个文件成为用户的可选输入

我已经看到了一些关于如何检查PHP格式的答案,但没有别的...... 棘手的部分是表单在引导框窗口内,所以我可能必须在message属性中插入代码......这是正确的吗?

回调解决方案:

<form name="uploadForm" action...>
callback: function (result) {
            if(result){
                document.uploadForm.submit();
            }
        }

1 个答案:

答案 0 :(得分:0)

  1. 您可以通过在按钮上添加onclick事件来提交表单,如下所示: jQuery的:

    $(&#39; button.submit_button&#39)。在({ click:function(event){     event.preventDefault();     $(本).closest(&#39;形式&#39;)。提交(); } });

  2. 您可以通过以下方式推荐任何文件信息:

    var file = document.forms [&#39; formName&#39;] [&#39; inputName&#39;]。files [0];

  3. 请参阅MDN上的FileAPI https://developer.mozilla.org/en-US/docs/Web/API/File

    1. 使用HTML5 Requered字段并在后端检查