user1511579
user1511579

Reputation: 1537

Get Form Element for Email Attachment

i pretend to pass the content of the attachment selected on an input type file to another php page where i will send the attachment by email.

It happens that i have this form declaration:

<form id="formElem" name="formElem" enctype="multipart/form-data" action="" method="post">

but i can't put the destination php page on action there because i pass through a jquery and a javascript function. It's in the last function that i redirect for the destination php page.

So, in that last javascript function i need to use this:

form.action = 'index.php?pagina=candB&'+ qstringA;

to redirect all the data of the form to the pretend php page. Before i was using this:

window.location.href = 'index.php?pagina=candB&'+ qstringA;

But as i was told here, this wouldn't allow to receive correctly the data of the attachment.

This is the button of the form where i do the submit:

<button name='send_cand' id='send_cand' value='send_cand' onclick='return false;' type='submit'>Send Data</button>

and it calls the following jquery function:

$('#send_cand').bind('click',function(){

    ....

    if($('#formElem').data('errors')){
        preenchimentoForm=false;

        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
        return false;
    }
    else{
        dadosFormularios(form, preenchimentoForm, cursos, empregos, eventos);
    }
}

And so, what i need to do is to apply to a var inside this function the form element so that i can pass her through the functions until here:

form.action = 'index.php?pagina=candB&'+ qstringA;

so that this line could work because right now it's not working.

Hope i was clear and a little help would be greatly appreciated. Thank yoy!

Upvotes: 1

Views: 134

Answers (1)

XQQ
XQQ

Reputation: 21

So you want to update the form action before submitting?

Try using the .submit() event and .attr() like this:

$('#formElem').submit(function(){

    // Update the form action        
    $('#formElem').attr('action', 'index.php?pagina=candB&'+ qstringA);

});

I tested this logic here: jsFiddle

Hope that helps!

Upvotes: 2

Related Questions