0

I have a form that I'm using to upload a photo and a message and I want to validate it using JQuery but it's not showing the success or error messages and I'm wondering if it's anything to do with the way I'm displaying the input field. Here is my code:

<form>
    <textarea id="formnote" rows="3"></textarea>
    <div id="chars"></div>
    <div class="formUploadLink">
        <a href="#" onclick="$('input[id=formmedia]').click();">
            <div class="sidebarSectionLink">Click here to add files</div>
        </a>
    </div>
    <div>
        <input type="hidden" id="formtype" value="photo" />
        <input type="file" id="formmedia" style="display: none;">
        <input type="hidden" id="formposter" value="<?php echo $yourid; ?>" />
    </div>
</form>

//Post Photo
$('#formmedia').blur(function()
{
    var pic=$("#formmedia").val();
    if(pic.length < 1)
    {
        $('.sidebarSectionLink').html("Please Add A Photo")
                                .removeClass("success")
                                .addClass("error");
        picok = 2;
    }
    else if(pic.indexOf('jpg') === -1 && pic.indexOf('jpeg') === -1 && pic.indexOf('png') === -1 && pic.indexOf('gif') === -1)
    {
        $('.sidebarSectionLink').html("Invalid File Format")
                                .removeClass("success")
                                .addClass("error");
        picok = 2;
    }
    else
    {
        picok = 1;
    }
});

I basically just want to validate the input and show if it's accepted in the .sidebarSectionLink div. Also, when it run the send button and have this code:

// Submit button action
$('#postThis').click(function()
{
    var type=$("#formtype").val();
    var note=$("#formnote").val();
    var media=$("#formmedia").val();
    var poster=$("#formposter").val();

    if(noteok == 1 && picok == 1)
    {           
        window.location.href = "php/add-media.php?type=type&note=note&media=media&poster=poster";
    }
});

Will this send the data as a link that can be sorted in the php file? I know that you can't post a file using JQuery post so I'm hoping that it works this way. Thank you.

4

0 回答 0