SitePoint Sponsor

User Tag List

Page 2 of 5 FirstFirst 12345 LastLast
Results 26 to 50 of 103
  1. #26
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I checked again and I have
    $mail->AddAddress($emailAddress);
    located in submit.php.

  2. #27
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought I solved it now I'm getting another PHP error.

  3. #28
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Philip, I assume I can style the gray box that with the thank you message ? What about a redirect after 5-6 seconds to another part of my page ?

  4. #29
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought I solved it now I'm getting another PHP error.
    Have you resolved your PHP problem yet? Do you want to post your submit.php code on this post?

    $mail->AddAddress($emailAddress);
    It was the presence of an assignment to $emailAddress that I was concerned about.

    The PHPmailer has a config.php file where the configuration parameters such as the smtp server are defined. Have you set up this file correctly?

  5. #30
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you resolved your PHP problem yet? Do you want to post your submit.php code on this post?
    I've fixed one problem, but the PHP error persists. Here is the error I currently get;

    Code PHP:
    Warning: require(phpmailer/class.phpmailer.php) [function.require]: failed to open stream: No such file or directory in /home/thecreat/public_html/construction/submit.php on line 2

    Here is the file submit.php.
    Code PHP:
    <?php
    require "phpmailer/class.phpmailer.php";
     
    session_name("fancyform");	/* starting the session */
    session_start();
     
    foreach($_POST as $k=>$v)
    {
    	/* if magic_quotes is enabled, strip the post array */
    	if(ini_get('magic_quotes_gpc'))
    	$_POST[$k]=stripslashes($_POST[$k]);
     
    	$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
    	/* escape the special chars */
    }
     
    $err = array();
     
    /* some error checks */
    if(!checkLen('name'))
    	$err[]='The name field is too short or empty!';
     
    if(!checkLen('email'))
    	$err[]='The email field is too short or empty!';
    else if(!checkEmail($_POST['email']))
    	$err[]='Your email is not valid!';
     
    if(!checkLen('subject'))
    	$err[]='You have not selected a subject!';
     
    if(!checkLen('message'))
    	$err[]='The message field is too short or empty!';
     
    /* compare the received captcha code to the one in the session array */
    if((int)$_POST['captcha'] != $_SESSION['expect'])
    	$err[]='The captcha code is wrong!';
     
    /* if there are errors */
    if(count($err))
    {
    	/* if the form was submitted via AJAX */
    	if($_POST['ajax'])
    	{
    		echo '-1';
    	}
     
    	/* else fill the SESSION array and redirect back to the form */
    	else if($_SERVER['HTTP_REFERER'])
    	{
    		$_SESSION['errStr'] = implode('<br />',$err);
    		$_SESSION['post']=$_POST;
     
    		header('Location: '.$_SERVER['HTTP_REFERER']);
    	}
     
    	exit;
    }
     
    /* the email body */
    $msg=
    'Name:	'.$_POST['name'].'<br />
    Email:	'.$_POST['email'].'<br />
    IP:	'.$_SERVER['REMOTE_ADDR'].'<br /><br />
     
    Message:<br /><br />
     
    '.nl2br($_POST['message']).'
     
    ';
     
    $mail = new PHPMailer();	/* using PHPMailer */
    $mail->IsMail();
     
    $mail->AddReplyTo($_POST['email'], $_POST['name']);
    $mail->AddAddress($emailAddress);
    $mail->SetFrom($_POST['email'], $_POST['name']);
    $mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";
     
    $mail->MsgHTML($msg);
     
    $mail->Send();
     
    unset($_SESSION['post']);	/* unsetting */
     
    /* the form was successfully sent */
    if($_POST['ajax'])
    {
    	echo '1';
    }
    else
    {
    	$_SESSION['sent']=1;
     
    	if($_SERVER['HTTP_REFERER'])
    		header('Location: '.$_SERVER['HTTP_REFERER']);
     
    	exit;
    }
     
    /* some helpful functions */
    function checkLen($str,$len=2)
    {
    	return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
    }
     
    function checkEmail($str)
    {
    	return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
    }
    ?>
    The configuration file for the form does not have any SMTP settings.

  6. #31
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would recommend that you post this as a problem on the PHP forum. Somebody there will undoubtedly be able to advise you better.

  7. #32
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Philip I'm in the process but can you remove the gray background where the line 'thank you message sent' appears?

  8. #33
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the grey background is from the "background" style in

    Code CSS:
    #Contact {
    	background: #C0C0C0;
    	overflow: hidden;
    	width: 650px;
    	margin: 40px 35px 0 300px;
    }

    changing it to

    background: #000000;

    should resolve the problem

  9. #34
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Philip, I need to have the form check that the fields are filled in before sending the form then displaying a thank you message, if a field is not filled in the form can't be sent.

  10. #35
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try replacing the javascript we added early with


    Code JavaScript:
    <script type="text/javascript">
    <!--
    $(document).ready(function(){
     
    		// Code for validation of form content
    		var name = $("#idname");
    		var email = $("#idemail");
    		var message = $("#idmessage");
    		var captcha = $("#id6_letters_code");
     
    		name.blur(validateName);
    		email.blur(validateEmail);
    		message.blur(validateMessage);
    		captcha.blur(validateCaptcha);
     
    		function validateName() {
    			var a = name.val();
    			if (a.length < 3) {
    				name.focus();
    				alert("Please supply your name");
    				return false;
    			}
    			return true;
    		}
     
    		function validateEmail() {
    			var a = email.val();
    			if (a.length == 0) {
    				email.focus();
    				alert("An Email address must be supplied");
    				return false;
    			}
    			if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(a)) {
    				email.focus();
    				alert("Email address is invalid");
    				return false;
    			}
    			return true;
    		}
     
     
    		function validateMessage() {
    			var a = message.val();
    			if (a.length < 10) {
    				message.focus();
    				alert("Please complete the message field");
    				return false;
    			}
    			return true;
    		}
     
    		function validateCaptcha() {
    			var a = captcha.val();
    			if (a.length != 6) {
    				captcha.focus();
    				alert("Captcha code is invalid");
    				return false;
    			}
    			return true;
    		}
     
     
    		// End of Code for validation of form content
     
     
        $("#contact_form").submit(function(e){
     
    		// Plus validation in submit
    		var invalid = !(validateName() && validateEmail() && validateMessage() && validateCaptcha());
    		if (invalid) return e.preventDefault();
     
            $.post('/construction/submit.php', $(this).serialize(),
                function(data){
                    var message;
                    if(parseInt(data)==-1)
                        message = "error";
                    else
                    {
                        $("#contact_form").hide('slow');
                        message = "Thank your for the message";
                    }
                    $("#contact_form").before('<p>' + message + '</p>');
                }
            );
            e.preventDefault();
        });
    });
    // -->
    </script>

    Your html for the form should become


    Code HTML4Strict:
    <form method="POST" id="contact_form" action="">
    <div class="name">
    <label for="idname">Name: </label>
    <input type="text" name="name" id="idname" value="">
    </div>
    <div class="name">
    <label for="idemail">Email: </label>
    <input type="text" name="email" id="idemail" value="">
    </div>
    <div class="message">
    <label for="idmessage">Message:</label>
    <textarea name="message" id="idmessage" rows="5" cols="30"></textarea>
    </div>
    <div class="captcha"><img src="./site_construction_a.php_files/captcha_code_file.php" id="captchaimg"></div>
    <div class="capcode">
    <label for="id6_letters_code">Enter (above) code here :</label>
    <input id="id6_letters_code" name="6_letters_code" type="text">
    </div>
    <div class="submit">
    <input type="submit" value="Submit" name="submit">
    </div>
    </form>

  11. #36
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, that works but could the notification be on the right hand side of each of the form fields then highlight the form field ? Also the CAPTCHA is not displaying, although it's in the HTML, unless I'm over looking something ?

  12. #37
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I looked over the HTML and fixed what I could but the CAPTCHA continues not to show on the page.

    What is going on with this line;
    Code JavaScript:
    (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(a)) {

  13. #38
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did a save as from your original page to develop the new code, this constructs a sub directory and puts associated files in it. I have then cut and pasted the html code which is where the problem has crept in.

    The src attribute of the img tag needs to be changed to reflect where it is on your site.

  14. #39
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, Philip could you past that part of the code so I can see which path it is, I've already tried a few but it's not working

    Also would it be possible to get the form fields that are not filled out not to have a pop up but instead on the right hand side of the form a text message and the form hightlights in red ?

  15. #40
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Philip I have solved the CAPTCHA problem. There remains something, the javascript is not submitted the form data using ajax as it should. If you want a link to the page in progress here.

  16. #41
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the function validateCaptcha you have modified the first line

    Code JavaScript:
                var a = getElemntById['id6_letters_code'].value;

    This results in an error. My original statement was

    Code JavaScript:
     var a = captcha.val();

    Why the change?

  17. #42
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also would it be possible to get the form fields that are not filled out not to have a pop up but instead on the right hand side of the form a text message and the form hightlights in red ?
    Your will need to add a style

    Code CSS:
    .error {
      color: #ff0000;
    }

    and modify the validation code


    Code JavaScript:
    $(document).ready(function(){
     
            // Code for validation of form content
            var name = $("#idname");
            var email = $("#idemail");
            var message = $("#idmessage");
            var captcha = $("#id6_letters_code");
     
            name.blur(validateName);
            email.blur(validateEmail);
            message.blur(validateMessage);
            captcha.blur(validateCaptcha);
     
            function validateName() {
    			name.parent().find('.error').remove();
                var a = name.val();
                if (a.length < 3) {
                	return reporterrormessage(name, "Please supply your name");
                }
                return true;
            }
     
            function validateEmail() {
    			email.parent().find('.error').remove();
                var a = email.val();
                if (a.length == 0) {
                	return reporterrormessage(email, "An Email address must be supplied");
                }
                if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(a)) {
                	return reporterrormessage(email, "Email address is invalid");
                }
                return true;
            }
     
     
            function validateMessage() {
    			message.parent().find('.error').remove();
                var a = message.val();
                if (a.length < 10) {
                	return reporterrormessage(message, "Please complete the message field");
                }
                return true;
            }
     
            function validateCaptcha() {
    			captcha.parent().find('.error').remove();
                var a = captcha.val();
                if (a.length != 5) {
                	return reporterrormessage(captcha, "Captcha code is invalid");
                }
                return true;
            }
     
     		function reporterrormessage (elem, msg) {
    			elem.parent().append('<span class="error">' + msg + '</span>');
    			elem.focus();
    			return false;
     		}
     
            // End of Code for validation of form content
     
     
        $("#contact_form").submit(function(e){
     
            // Plus validation in submit
            var invalid = !(validateName() && validateEmail() && validateMessage() && validateCaptcha());
            if (invalid) return e.preventDefault();
     
            $.post('/construction/submit.php', $(this).serialize(),
                function(data){
                    var message;
                    if(parseInt(data)==-1)
                        message = "error";
                    else
                    {
                        $("#contact_form").hide('slow');
                        message = "Thank your for the message";
                    }
                    $("#contact_form").before('<p>' + message + '</p>');
                }
            );
            e.preventDefault();
        });
    });

    Hope you are learning something from this exercise

  18. #43
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I may be misunderstanding on what you wrote here. I have the following Javascript for the CAPTCHA;


    Code JavaScript:
            function validateCaptcha() {
                captcha.parent().find('.error').remove();
                var a = captcha.val();
                if (a.length != 5) {
                    return reporterrormessage(captcha, "Captcha code is invalid");
                }
                return true;
            }

    The javascript continues not to submit the form data ! I am learning, taking it one step at a time but learning

  19. #44
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the error is probably occurring in submit.php

    I was getting the message

    Code JavaScript:
    <br />
    <b>Fatal error</b>:  Class 'SMTP_validateEmail' not found in <b>/home/thecreat/public_html/construction/submit.php</b> on line <b>77</b><br />

  20. #45
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me look into it. What about the CAPTCHA code you were talking about ?

  21. #46
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What about the CAPTCHA code you were talking about ?
    Are you referring to my comments on

    Code JavaScript:
    var a = getElemntById['id6_letters_code'].value;

    If so - we have replaced the code with what I posted to put the error message alongside the input area.

  22. #47
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, why isn't the javascript communicating with the server PHP script I have. The form submits the thank-you message occurs but no email is sent.

  23. #48
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As i posted before what is returned from submit.php is

    Code HTML4Strict:
    <br />
    <b>Fatal error</b>:  Class 'SMTP_validateEmail' not found in <b>/home/thecreat/public_html/construction/submit.php</b> on line <b>77</b><br />

    because it is not the value -1 it gives the thank you message. It might be sensible to change the code

    Code JavaScript:
    message = "Thank your for the message";

    to

    Code JavaScript:
    message = data;

  24. #49
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Philip, as seen on the page I is it possible to not only have the error message if an area of the form is skipped but the form box turn red ? Once the thank you message occurs a delay of 3-4 seconds and the page gets redirected to the main page.

  25. #50
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add a style

    Code CSS:
    .fldinerror {
     border: 1px solid #ff0000;
    }

    and then use the modified javascript

    Code JavaScript:
    <script type="text/javascript">
    <!--
    $(document).ready(function(){
     
            // Code for validation of form content
            var name = $("#idname");
            var email = $("#idemail");
            var message = $("#idmessage");
            var captcha = $("#id6_letters_code");
     
            name.blur(validateName);
            email.blur(validateEmail);
            message.blur(validateMessage);
            captcha.blur(validateCaptcha);
     
            function validateName() {
                name.parent().find('.error').remove();
                name.removeClass("fldinerror");
                var a = name.val();
                if (a.length < 3) {
                    return reporterrormessage(name, "Please supply your name");
                }
                return true;
            }
     
            function validateEmail() {
                email.parent().find('.error').remove();
                email.removeClass("fldinerror");
                var a = email.val();
                if (a.length == 0) {
                    return reporterrormessage(email, "An Email address must be supplied");
                }
                if (!/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/.test(a)) {
                    return reporterrormessage(email, "Email address is invalid");
                }
                return true;
            }
     
     
            function validateMessage() {
                message.parent().find('.error').remove();
                message.removeClass("fldinerror");
                var a = message.val();
                if (a.length < 10) {
                    return reporterrormessage(message, "Please complete the message field");
                }
                return true;
            }
     
            function validateCaptcha() {
                captcha.parent().find('.error').remove();
                captcha.removeClass("fldinerror");
                var a = captcha.val();
                if (a.length != 6) {
                    return reporterrormessage(captcha, "Captcha code is invalid");
                }
                return true;
            }
     
           function reporterrormessage (elem, msg) {
           		elem.addClass("fldinerror");
                elem.parent().append('<span class="error">' + msg + '</span>');
                elem.focus();
                return false;
           }
     
            // End of Code for validation of form content
     
     
        $("#contact_form").submit(function(e){
     
            // Plus validation in submit
            var invalid = !(validateName() && validateEmail() && validateMessage() && validateCaptcha());
            if (invalid) return e.preventDefault();
     
            $.post('/construction/submit.php', $(this).serialize(),
                function(data){
                    var message;
                    if(parseInt(data)==-1)
                        message = "error";
                    else
                    {
                        $("#contact_form").hide('slow');
                        message = "Thank your for the message";
                    }
                    $("#contact_form").before('<p class="thankyou">' + message + '</p>');
    				setTimeout(function () {
    						$("#content").children().hide();
    			            $("#contact_form").show();
    			            $("#contact_form").parent().find('.thankyou').remove();
    						$("#intro").show();
    					}, 3000);
                }
            );
            e.preventDefault();
        });
    });
    // -->
    </script>


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
  •