Skip to content

Instantly share code, notes, and snippets.

@MikSDigital
Last active August 29, 2015 14:21
Show Gist options
  • Save MikSDigital/c457a397cf0dbb20b2b1 to your computer and use it in GitHub Desktop.
Save MikSDigital/c457a397cf0dbb20b2b1 to your computer and use it in GitHub Desktop.
Получает имя файла при отсылке через форму
<!-- Contact form -->
<form id="contact-form" class="contact-form" name="" method="POST" action="http://site.ee/ru/message-sent.htm" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<legend>Me koostame hinnapakkumise ja saadame selle Teile juba ühe tunni jooksul!</legend>
<div class="input-field">
<input type="text" placeholder="Nimi:" value="" name="name" required>
</div>
<div class="input-field">
<input type="text" placeholder="Telefon:" value="" name="phone" required>
</div>
<div class="input-field">
<input type="email" placeholder="E-mail" value="" name="email">
</div>
<div class="input-upload">
<input type="file" name="attachment" value="" />Lisa fail</div>
<span id="attachment"></span>
<div class="input-field">
<textarea placeholder="Kirjuta tekst siia" id="message" rows="15" name="message"></textarea>
</div>
<button type="submit" id="submit" name="submit">Saada päring</button>
</form>
<!-- Contact form -->
$('input[type="file"]').on('change', function (event, files, label) {
var file_name = this.value.replace(/\\/g, '/').replace(/.*\//, '');
$('#attachment').text(file_name);
});
$( "button" ).click(function() {
$( "#contact-form" ).submit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment