SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact Form help

    Hi everybody,

    I really need your guys help as i have built a website and have added two contact forms. Which i managed to get from a tutorial off youtube. Now the contact duplicated the forms and have put one on the home and contact form page. they both work and is able to send the emails but on the home page it loses its footer and introduction part and on the contact form page it looses its footer. And I have run out off ideas on what to do.

    So if anyone has got a solution of fixing it or better way of inputting a contact form pleeessssee giv me a shout

    many thanks

    Anthony

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me kno if you want code or link to the website

  3. #3
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,286
    Mentioned
    181 Post(s)
    Tagged
    4 Thread(s)
    Can you be more specific?

    What do you mean "it looses its footer"? (BTW, the correct word in this case is lose, not loose)
    If the footer on the page(s) disappears when you insert the form, then I would suspect you have not properly closed an HTML tag in the form. Or you have inserted the form in such a way that it leaves a dangling tag.
    Have you viewed the page(s) in various browsers? Some browsers are more forgiving of such errors.
    Have you tried a tool like Firebug or the "view element" in Chrome to spot the error?
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Gonna need to see the code to answer the question. Entirely too vague.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by StarLion View Post
    Gonna need to see the code to answer the question. Entirely too vague.
    this is the website: www.all-wired.co.uk

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Looks like you've got a malformed <script> tag when you submit the form.... what's the actual code that handles the submission?
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    // Set email variables
    $email_to '';
    $email_subject 'Form submission';

    // Set required fields
    $required_fields = array('fullname','contact','email','comment');

    // set error messages
    $error_messages = array(
        
    'fullname' => 'Please enter a Name to proceed.',
        
    'contact' => 'Please enter a Contact Number to proceed.',
        
    'email' => 'Please enter a valid Email Address to continue.',
        
    'comment' => 'Please enter your Message to continue.'
    );

    // Set form status
    $form_complete FALSE;

    // configure validation array
    $validation = array();

    // check form submittal
    if(!empty($_POST)) {
        
    // Sanitise POST array
        
    foreach($_POST as $key => $value$_POST[$key] = remove_email_injection(trim($value));
        
        
    // Loop into required fields and make sure they match our needs
        
    foreach($required_fields as $field) {        
            
    // the field has been submitted?
            
    if(!array_key_exists($field$_POST)) array_push($validation$field);
            
            
    // check there is information in the field?
            
    if($_POST[$field] == ''array_push($validation$field);
            
            
    // validate the email address supplied
            
    if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation$field);
        }
        
        
    // basic validation result
        
    if(count($validation) == 0) {
            
    // Prepare our content string
            
    $email_content 'New Website Comment: ' "\n\n";
            
            
    // simple email content
            
    foreach($_POST as $key => $value) {
                if(
    $key != 'submit'$email_content .= $key ': ' $value "\n";
            }
            
            
    // if validation passed ok then send the email
            
    mail($email_to$email_subject$email_content);
            
            
    // Update form switch
            
    $form_complete TRUE;
        }
    }

    function 
    validate_email_address($email FALSE) {
        return (
    preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i'$email))? TRUE FALSE;
    }

    function 
    remove_email_injection($field FALSE) {
       return (
    str_ireplace(array("\r""\n""%0a""%0d""Content-Type:""bcc:","to:","cc:"), ''$field));
    }

    ?>
    Last edited by ParkinT; Jul 19, 2012 at 08:38. Reason: Added BB tags to format code for easier reading

  8. #8
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this the one?

  9. #9
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    k, not seeing anything glaringly obvious that would cause that... step back a layer and show me the code for the form itself? (PS: wrap them in [ PHP ] [ /PHP ] tags (no spaces))
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <div id="formwrap">
    <div id="form">
    <?php if($form_complete === FALSE): ?>
    <form action="contactform.php" method="post" id="comments_form">
    <div class="row">
    <div class="label">Your Name</div><!-----end .label----->
    <div class="input">
    <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>
    </div><!-----end .input----->
    </div><!-----end .row----->

    <div class="row">
    <div class="label">Contact Number</div><!-----end .label----->
    <div class="input">
    <input type="text" id="contact" class="detail" name="contact" value="<?php echo isset($_POST['contact'])? $_POST['contact'] : ''; ?>" /><?php if(in_array('contact', $validation)): ?><span class="error"><?php echo $error_messages['contact']; ?></span><?php endif; ?>
    </div><!-----end .input----->
    </div><!-----end .row----->

    <div class="row">
    <div class="label">Your Email Address</div><!-----end .label----->
    <div class="input">
    <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" /><?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?>
    </div><!-----end .input----->
    </div><!-----end .row----->

    <div class="row">
    <div class="label">Your Message</div><!-----end .label----->
    <div class="input">
    <textarea id="comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea><?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>
    </div><!-----end .input----->
    </div><!-----end .row----->

    <div class="submit">
    <input type="submit" id="submit" name="submit" value="Send Message" />
    </form>
    <?php else: ?>
    <p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
    <script type="text/javascript">
    setTimeout('ourRedirect()', 5000)
    function ourRedirect(){
    location.href='contactform.php'
    }
    <?php endif; ?>


    </div><!-----end .submit----->




    </div><!-----end form----->
    </div><!-----end of form wrap----->

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Ah, there it is...
    Code:
    <?php else: ?>
    <p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
    <script type="text/javascript">
    setTimeout('ourRedirect()', 5000)
    function ourRedirect(){
    location.href='contactform.php'
    }
    <?php endif; ?>
    Do you see a </script> on the end of that 4-line javascript code? I dont....
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    O yeah, thanks Star Lion. But Ive jus added the </script> but the footer still moves on both the home and contact form page, if you try it.

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is it possible to add a reCAPTCHA to this form by any chance? if so, how do I go about adding one?

  14. #14
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,601
    Mentioned
    411 Post(s)
    Tagged
    7 Thread(s)
    Ew, captcha is horrible. Have a read of this thread for much better options:

    http://www.sitepoint.com/forums/show...=1#post5144556

  15. #15
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    Mkay, this time it's an errant </div> tag...

    [QUOTE=Tony_b;5153635]
    Code:
        <div class="submit">
        <input type="submit" id="submit" name="submit" value="Send Message" />    
        </form>	
    	<?php else: ?>
    <p style=" font-size:25px; font-family:Arial, Helvetica, sans-serif; color:#333333; margin-left:25px;">Thank You For Your Request</p>
    <script type="text/javascript">
    setTimeout('ourRedirect()', 5000)
    function ourRedirect(){
     location.href='contactform.php'
     }
    <?php endif; ?>
    
    
      </div><!-----end .submit----->
    Notice how the opening tag for the div is inside the "if" part of the if/else? Well, when we run the ELSE (the form has been submitted), there is no opening tag for that </div>, so it closes the next element up the chain - which causes your alignment issue. Move the offending line (the bottom one) to just below the submit button's input tag.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •