...

View Full Version : unsure of what this means? <?=$css?>



LJackson
01-27-2010, 10:38 PM
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

ninnypants
01-27-2010, 10:43 PM
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

Len Whistler
01-27-2010, 10:55 PM
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:


$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



---------

LJackson
01-27-2010, 11:04 PM
thanks for clearing that up for me :)


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

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

LJackson
01-27-2010, 11:15 PM
the problem seems to be with the submit.php file, if i turn off js and submit the form i get more errors :(


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

/* 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?

LJackson
01-27-2010, 11:21 PM
ok its now working without js but not with js :(

surley a matter of time before it starts to work :D

Len Whistler
01-27-2010, 11:34 PM
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


require "phpmailer/class.phpmailer.php";

session_name("fancyform");
session_start();



----------

ninnypants
01-28-2010, 03:45 AM
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.

LJackson
01-28-2010, 01:18 PM
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

LJackson
01-28-2010, 02:27 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum