Johnain Posted November 22, 2007 Share Posted November 22, 2007 Hi people I am an experienced VFP and ABAP developer with a pretty good grasp of HTML, and recently XHTML. I have always been alittle wary of web based languages (fear of the unknown !) but now I have started with PHP I really like it. My problem is (I think) with the scope of variables. I have two php pages for the user to send an e-mail, one in French and the other in English. They both build the same form with the same variables, but their HTML text is in different languages. The form's action in each both call the same "validate and send" php page. Within each "sending" form I create a variable called $langg and set it to EN or FR so I can send out different language texts and <a> jumps afterwards depending on the language. In the French sending form I say ... $langgi = "FR"; <input type="hidden" name="langg" value="<?php echo $langgi ?>" /> I do not understand how debuggers work so in my target "validate and send" form I first interpret the lanng variable ... $langg = $_POST['langg']; ... and then put in an echo to see what I get ... <table> <tr><td><?php echo $_POST['langg']; ?></td></tr> <tr><td><?php echo $langg; ?></td></tr> </table> Row 1 gives EN and Row 2 gives FR Is this a scope issue? Can anybody see what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/ Share on other sites More sharing options...
adam291086 Posted November 22, 2007 Share Posted November 22, 2007 i am a little confused. Are you having problems with changing the form to be either in english or french? What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396594 Share on other sites More sharing options...
Johnain Posted November 22, 2007 Author Share Posted November 22, 2007 Hi Thanks for the reply I want the user visible stuff in my form to be in french or english. Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396595 Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 well have to see a little more of your code to tell you that could be a scope issue could be its getting overwritten somewhere.. Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396596 Share on other sites More sharing options...
adam291086 Posted November 22, 2007 Share Posted November 22, 2007 well this may be a long way around but i dont have a lot of php knowledge. Have a bit before the form that say ''english or french''. Then submit that info to a php page. Then create and IF statement that says if ($lang = french) { echo //all your html that makes the french form; } else echo //all the english form hope this give you an idea. My If statement may be wrong as i can check it out as i am at work. Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396600 Share on other sites More sharing options...
Johnain Posted November 22, 2007 Author Share Posted November 22, 2007 well have to see a little more of your code to tell you that could be a scope issue could be its getting overwritten somewhere.. Hi Rajiv. Thanks for your interest. I have not put all of the multi-ling code in, just some bits, but here it is ----------------------------------------------------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Le Pré De Barre :Contact us</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="../css/style1.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <div id="sitebranding"> <?php $langg = $_POST['langg']; ?> <h1>Le Pré De Barre </h1> </div> <div id="tagline"> <?php if ($_POST['langg']="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> </div><!-- end of tagline div --> </div> <!-- end of header div --> <div id="navigation"> <ul> <li><a href="../index.html">Home</a></li> </ul> </div> <!-- end of navigation div --> <div id="bodycontent"> <table> <tr><td><?php echo $_POST['langg']; ?></td></tr> <tr><td><?php echo $langg; ?></td></tr> </table> <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes']; $attn = $_POST['attn']; $country = $_POST['country']; $agerange = $_POST['agerange']; $telephone = $_POST['telephone']; $gender = $_POST['gender']; $errorreported = 0; $errortext = ""; if (eregi('http:', $notes)) { $errorreported = 1; $errortext = "1"; echo "<p>Please do not insert web addresses in your mail</p>"; } if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,"."))) { $errorreported = 2; $errortext = $errortext.' 2'; echo "<p>You have not entered a valid e-mail address.</p>"; } if(empty($visitor) || empty($visitormail) || empty($notes )) { $errorreported = 3; $errortext = $errortext.' 3'; echo "<p>We need your e-mail address, name and message content before we can send an e-mail.</p>"; } if($errorreported > 0 and $langg = "EN") { echo "<p>Sorry, your e-mail has not been sent yet because it contains an error or is incomplete.</p>"; ?> <p><a href="contact.php">Click here to return to your e-mail</a></p> <?php die (); } if($errorreported > 0 and $langg = "FR") { echo "<p>Désolé, votre E-mail n'a pas été envoyé encore parce qu'il contient une erreur ou est inachevé.</p>"; ?> <p><a href="contactfr.php">Clic ici à retourner à votre E-mail</a></p> <?php die (); } $todayis = date("l, F j, Y, g:i a") ; $attn = $attn ; $subject = $attn; $notes = stripcslashes($notes); $message = " $todayis [EST] \n Attention: $attn \n Message: $notes \n Age Range: $agerange\n Telephone: $telephone\n Gender: $gender\n Country: $country\n From: $visitor ($visitormail)\n Additional Info : IP = $ip \n Browser Info: $httpagent \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; mail("[email protected]", $subject, $message, $from) ?> <p align="center"> Date: <?php echo $todayis ?> <br /> Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) <br /> Attention: <?php echo $attn ?> <br /> Message:<br /> <?php $notesout = str_replace("\r", "<br/>", $notes); echo $notesout; ?> <br /> <?php echo $ip ?> <br /><br /> <a href="../index.html"> Continue </a> </p> </div><!-- end of bodycontent div --> <div id="rightcol"> <table> <tr> <td style="width:150 align:right"><img src="../images/yippee.jpg" width="135" height="157" border="0" alt="Yippee !"></td> </tr> <tr> <td><img src="../images/3lpdb.gif" width="135" height="332" border="0" alt=""></td> </tr> </table> </div> <!-- End of rightcol div --> </body> </html> ----------------------------------------------------------------------- Regards and thanks John Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396604 Share on other sites More sharing options...
Johnain Posted November 22, 2007 Author Share Posted November 22, 2007 well this may be a long way around but i dont have a lot of php knowledge. Have a bit before the form that say ''english or french''. Then submit that info to a php page. Then create and IF statement that says if ($lang = french) { echo //all your html that makes the french form; } else echo //all the english form hope this give you an idea. My If statement may be wrong as i can check it out as i am at work. Thanks for that Adam. I appreciate your help. This, however is the equivalent of having two php files with two sets of logic to maintain, and I am trying to avoid that if I can. Regards john Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396608 Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 here is your problem <?php if ($_POST['langg']="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> should be <?php if ($_POST['langg']=="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']=="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> notice the "==" a "=" is for assignment Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396614 Share on other sites More sharing options...
adam291086 Posted November 22, 2007 Share Posted November 22, 2007 You can get a form to submit to itself for validation reasons i've seen it happen on here. So you wouldn't require two pages. rajivgonsalves has more experience then me so was able to pick up the coding problem quicker than me. Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396617 Share on other sites More sharing options...
Johnain Posted November 22, 2007 Author Share Posted November 22, 2007 here is your problem <?php if ($_POST['langg']="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> should be <?php if ($_POST['langg']=="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']=="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> notice the "==" a "=" is for assignment Please regard yourself as a superstar. I will try it now. Looks like I have got plenty of learning to do. But no surprises there. I am looking forward to it. Regards and thanks Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396619 Share on other sites More sharing options...
Johnain Posted November 22, 2007 Author Share Posted November 22, 2007 here is your problem <?php if ($_POST['langg']="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> should be <?php if ($_POST['langg']=="EN"){ echo "<p>Training and supporting the horse and rider </p>"; } elseif ($_POST['langg']=="FR"){ echo"<p>Formant et soutenant le cheval et le cavalier </p>" ; } else { echo "<p>Training and supporting the horse and riderrrrrrr </p>" ; } ?> notice the "==" a "=" is for assignment Please regard yourself as a superstar. I will try it now. Looks like I have got plenty of learning to do. But no surprises there. I am looking forward to it. Regards and thanks That works. Thanks very much. Mrs Johnain no longer frightened to come in the room Regards and thanks John Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396620 Share on other sites More sharing options...
rajivgonsalves Posted November 22, 2007 Share Posted November 22, 2007 Your welcome glad to be of help Quote Link to comment https://forums.phpfreaks.com/topic/78377-solved-new-boy-has-problem-with-the-scope-of-variables/#findComment-396623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.