Home › Forums › Porto – Responsive HTML5 Template › Multi file form
- This topic has 11 replies, 2 voices, and was last updated 4 years, 6 months ago by Support2. This post has been viewed 624 times
-
AuthorPosts
-
September 3, 2019 at 10:39 pm #10030643pesaindonParticipant
Hi, I would like to use the advanced form with a multiple file input — <input class=”d-block” type=”file” name=”attachment” id=”attachment” multiple> — what is needed in PHP to email multi files Thank You
September 4, 2019 at 5:31 am #10030644Support2KeymasterHello, thanks for your purchase.
1) First change the HTML of input to:
<input class="d-block" type="file" name="attachment[]" id="attachment" multiple>
2) Change the attachment PHP code to:
// Step 4 - If you don't want to attach any files, remove that code below if (isset($_FILES['attachment'])) { for($i=0; $i < count($_FILES['attachment']['tmp_name']); $i++){ $mail->AddAttachment($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]); } }
Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
September 4, 2019 at 12:04 pm #10030648pesaindonParticipantHi Rodrigo,
Great job on the multiple file input PHP code! I’m sorry but I should of mentioned I would like the file(s) select to be optional. Currently, if I don’t attach a file(s) I get an error. “Error! There was an error sending your message. Could not access file:” What is needed in PHP to make attach file(s) optional? Also, I’m not sure why it is doing this but when I hit “Send” my page scrolls up to the top of site. Any ideas on this as well?
Thank You
Paul
September 4, 2019 at 10:31 pm #10030659Support2KeymasterHello Paul,
Right.
Please change the attachment code to:
// Step 4 - If you don't want to attach any files, remove that code below if (isset($_FILES['attachment']) && !empty($_FILES['attachment']['name'][0]) ) { for($i=0; $i < count($_FILES['attachment']['tmp_name']); $i++){ $mail->AddAttachment($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]); } }
Regarding “Send” button scrolling issue we couldn’t reproduce here. Can you please send a online test link with your website for us, so we can inspect your code and discover where is the issue and how to solve that.
Kind Regards,
Rodrigo.
September 5, 2019 at 1:46 am #10030668pesaindonParticipantHi,
The code worked perfectly. Thank You very much. I will send a private reply with web address.
September 5, 2019 at 1:48 am #10030669pesaindonParticipantThis reply has been marked as private.September 5, 2019 at 3:58 am #10030670Support2KeymasterHello Paul,
It’s because you are using two contact forms on the same page. Then you need unique id for the anchor on each contact form.
Try changing the anchor ID of the contact form to:
.. .. . .. <h3 class="mb-1 text-5">Send a <strong class="font-weight-extra-bold">Quick</strong> Message to the <strong class="font-weight-extra-bold">Best</strong> Recycling Center Around!</h3> <div class="offset-anchor" id="contact-sent2"></div> <form id="contactFormAdvanced" action="index.php#contact-sent2" method="POST" enctype="multipart/form-data"> <input type="hidden" value="true" name="emailSent" id="emailSent"> <div class="form-row"> ... ... .
Please, try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
September 5, 2019 at 10:24 am #10030675pesaindonParticipantHi Rodrigo,
Everything functioning fine.
Thank You Very Much
Paul
September 5, 2019 at 11:32 am #10030676pesaindonParticipantThis reply has been marked as private.September 6, 2019 at 6:53 am #10030683Support2KeymasterHello Paul,
1) Really has an issue with sticky heade and side panel. Sorry for that. To fix please add this code in (js/custom.js):
$('.side-panel-toggle').on('click', function(e){ if( $(window).scrollTop() > $('#header').offset().top ) { $('html').addClass('sticky-header-active'); } })
2) It´s because you are using two advanced contact forms on the same page. In that it´s necessary some changes on the code. Please change the code of contact form on bottom of page (not inside side panel):
<?php if (isset($arrResult) && isset($_POST['emailSent2'])) { if($arrResult['response'] == 'success') { ?> <div class="alert alert-success" id="contactSuccess"> <strong>Success!</strong> Your message has been sent to us. </div> <?php } else if($arrResult['response'] == 'error') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> There was an error sending your message. <span class="font-size-xs mt-2 d-block" id="mailErrorMessage"><?php echo $arrResult['errorMessage'];?></span> </div> <?php } else if($arrResult['response'] == 'captchaError') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> Verification failed. </div> <?php } } ?>
* This code is above the contact form on bottom of page.
Also change the input hidden
emailSent
to:<input type="hidden" value="true" name="emailSent2" id="emailSent2">
On the PHP part on top of page change the “if” to:
if(isset($_POST['emailSent']) || isset($_POST['emailSent2'])) {
On the PHP code that shows success/error messages inside the side panel change to:
<?php if (isset($arrResult) && isset($_POST['emailSent'])) { if($arrResult['response'] == 'success') { ?> <div class="alert alert-success" id="contactSuccess"> <strong>Success!</strong> Your message has been sent to us. </div> <?php } else if($arrResult['response'] == 'error') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> There was an error sending your message. <span class="font-size-xs mt-2 d-block" id="mailErrorMessage"><?php echo $arrResult['errorMessage'];?></span> </div> <?php } else if($arrResult['response'] == 'captchaError') { ?> <div class="alert alert-danger" id="contactError"> <strong>Error!</strong> Verification failed. </div> <?php } } ?>
Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
September 7, 2019 at 10:23 am #10030692pesaindonParticipantThis reply has been marked as private.September 9, 2019 at 10:26 pm #10030701Support2KeymasterHello Paul,
1) Reload the page is the default behavior of Advanced Contact Form when sends the message and unfortunately this is the only way. But we can create a custom code that detects when the form inside the side panel is sent and then open the side panel to show the success message. For it please this code below in (js/custom.js):
$(window).on('load', function(){ if( window.location.hash == '#contact-sent' ) { $('.side-panel-toggle').trigger('click'); } });
* This will detect when the form inside side panel is sent and then automatically open the panel to show the messages.
2) This is the default behavior for the Advanced Contact Form. This occurs because when send the page reloads and detect the #contact-sent2 anchor and scroll down.
3) Oh right. We need exclude this field from the message. On the PHP part at top of page change the condition code to this new:
if( !in_array( $label, array( 'emailSent', 'emailSent2', 'captcha' ) ) ) {
Please try that and let us know if you need further assistance.
Kind Regards,
Rodrigo.
-
AuthorPosts
This topic is marked as "RESOLVED" and can not rceive new replies.