Use a variável JS na ação do formulário
<script> var url = foo(); </script>
<form method="POST" action=""+url enctype="multipart/form-data">
NachooCh
<script> var url = foo(); </script>
<form method="POST" action=""+url enctype="multipart/form-data">