Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts

    Exclamation unsure of what this means? <?=$css?>

    hi all,

    my contact form was working fine but my host recently upgraded there servers upgraded from PHP 5.2 to PHP 5.3 and now my contact form doesnt work and im getting a few warning/errors showing up on the page.

    one relates to this
    <?=$css?>

    the error is Undefined variable: css

    not sure what <?=$css?> means any help would be appreciated

    cheers

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    it is a short code for echo. If you have short tags enabled you can use

    <?=$css ?>

    instead of

    <?php echo $css; ?>

    so it's likely that you haven't set $css to a value

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    A quick fix - but not recommended - would be to put error_reporting(0); at the top of your header file. Is the $css value coming from $_GET['css']? If so then this should work:

    PHP Code:
    $css = isset($_GET['css']) ? $_GET['css'] : 1//Defaults to 1 or whatever you require 
    I think PHP 5.3 requires all variables to be defined, while they didn't have to be in PHP 5.2



    ---------
    Leonard Whistler

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    thanks for clearing that up for me

    Quote Originally Posted by Len Whistler View Post
    Is the $css value coming from $_GET['css']?
    not sure mate, i found an ajax contact form on the net which i really liked and got it working only to have it messed up by the upgrade

    ive got this section of code which seems to set the value of css but this throws up an error RE: undefined sent
    PHP Code:
    if($_SESSION['sent'])
    {
        
    $success='<h1>Thank you!</h1>';
        
        
    $css='<style type="text/css">#contact-form{display:none;}</style>';
        
        unset(
    $_SESSION['sent']);

    so i put it in isset tags and that solves that one, but my form never submits?

    no more errors but still not working
    do you want to see the code in full?

    cheers
    Luke

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    the problem seems to be with the submit.php file, if i turn off js and submit the form i get more errors

    Code:
    Notice: Undefined index: ajax in /customers/kernow-connect.com/kernow-connect.com/httpd.www/contact_data/submit.php on line 47
    
    Warning: Cannot modify header information - headers already sent by (output started at /customers/kernow-connect.com/kernow-connect.com/httpd.www/contact_data/submit.php:47) in /customers/kernow-connect.com/kernow-connect.com/httpd.www/contact_data/submit.php on line 57
    here is the submit code
    PHP Code:
    <?php

    /* config start */

    $emailAddress '';

    /* config end */


    require "phpmailer/class.phpmailer.php";

    session_name("fancyform");
    session_start();


    foreach(
    $_POST as $k=>$v)
    {
        if(
    ini_get('magic_quotes_gpc'))
        
    $_POST[$k]=stripslashes($_POST[$k]);
        
        
    $_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
    }


    $err = array();

    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!';

    if((int)
    $_POST['captcha'] != $_SESSION['expect'])
        
    $err[]='The captcha code is wrong!';


    if(
    count($err))
    {
        if(
    $_POST['ajax'])
        {
            echo 
    '-1';
        }

        else if(
    $_SERVER['HTTP_REFERER'])
        {
            
    $_SESSION['errStr'] = implode('<br />',$err);
            
    $_SESSION['post']=$_POST;
            
            
    header('Location: '.$_SERVER['HTTP_REFERER']);
        }

        exit;
    }


    $msg=
    'Name:    '.$_POST['name'].'<br />
    Email:    '
    .$_POST['email'].'<br />
    IP:    '
    .$_SERVER['REMOTE_ADDR'].'<br /><br />

    Message:<br /><br />

    '
    .nl2br($_POST['message']).'

    '
    ;


    $mail = new 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']);

    if(
    $_POST['ajax'])
    {
        echo 
    '1';
    }
    else
    {
        
    $_SESSION['sent']=1;
        
        if(
    $_SERVER['HTTP_REFERER'])
            
    header('Location: '.$_SERVER['HTTP_REFERER']);
        
        exit;
    }

    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);
    }

    ?>
    if i put if(isset($_POST['ajax']........ then the form just reloads the form again once i press submit?

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    ok its now working without js but not with js

    surley a matter of time before it starts to work

  • #7
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I will take a quick guess on this one.

    "Warning: Cannot modify header information - headers already sent by ......"

    There can't be HTML output, including white space before session_start(), and phpmailer.php might have HTML output and/or white space

    PHP Code:
    require "phpmailer/class.phpmailer.php";

    session_name("fancyform");
    session_start(); 


    ----------
    Leonard Whistler

  • #8
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    The first error is likely causing the second error, so you need to always have the ajax field in the form but have it set to 0 or something like that.

  • #9
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    for some reason the error messages have now gone when i fixed the others which is good but the form no longer submits when using ajax it seems to be ok without ajax but something is causing it to mess up somewhere?

    just not sure where and why lol

    cheers
    Luke

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,097
    Thanks
    297
    Thanked 12 Times in 12 Posts
    think its my js which is messing up?

    i have an old working file which will still work but it Interferes with another js function on the page which is annoying to say the least

    perhaps if i head over to the js section they might be best to help me sort it out?

    grrr lol why does nothing go to plan?
    cheers


  •  

    Posting Permissions

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