Multi file form

Home Forums Porto – Responsive HTML5 Template Multi file form

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #10030643
    pesaindon
    Participant

    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


    #10030644
    Support2
    Keymaster

    Hello, 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.


    #10030648
    pesaindon
    Participant

    Hi 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


    #10030659
    Support2
    Keymaster

    Hello 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.


    #10030668
    pesaindon
    Participant

    Hi,

    The code worked perfectly. Thank You very much. I will send a private reply with web address.


    #10030669
    pesaindon
    Participant
    This reply has been marked as private.
    #10030670
    Support2
    Keymaster

    Hello 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.


    #10030675
    pesaindon
    Participant

    Hi Rodrigo,

    Everything functioning fine.

    Thank You Very Much
    Paul


    #10030676
    pesaindon
    Participant
    This reply has been marked as private.
    #10030683
    Support2
    Keymaster

    Hello 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.


    #10030692
    pesaindon
    Participant
    This reply has been marked as private.
    #10030701
    Support2
    Keymaster

    Hello 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.


Viewing 12 posts - 1 through 12 (of 12 total)

This topic is marked as "RESOLVED" and can not rceive new replies.