Jump to content

[SOLVED] passing content of $_GET['variable'] to $variable


Recommended Posts

This works in my script:

------------------------

echo $_GET['variable'];

------------------------

 

But this does not:

------------------------

$test = $_GET['variable'];

echo $test;

------------------------

 

example url

------------------------------------------------

http://www.mysite.com/page.html?variable=string

------------------------------------------------

 

I'm using modx.

Is it possible that the issue is a modx, PHP configuration, or server issue?

 

If so are there are any work arounds?

 

-Thanks-

 

I noticed that was an html page. If your server isn't configured to parse PHP in html pages (.html or .htm pages) then than may be causing the problem. However, if you can successfully echo the $_GET variable, then i'm not so sure. Is there no other code that could be impacting things?

 

Do you have error reporting on?

 

try adding

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

at the top of your script so you can see if there are any errors being output

This is the code copied exactly from the script

<?php $test = $_GET['service']; ?>
<h1>Request Service  <?php echo $_GET['service']; echo $test; ?></h1>

 

the url http://www.mysite.com/test.php?service=wtf renders this

Request Service wtf
Notice: Undefined variable: test

 

here's the entire script

<?php
/*-----  Need to do 
 - Compare email with validation email 
 - add how did you hear about us? 
 - phone number validation 
 - non required fields validation? -------*/

$url = $modx->makeUrl($modx->documentIdentifier,"", "", "full");

function gen_verify($length = 10) { 
  $verify = NULL;
  $chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"; 
  for($i = 0; $i < $length; $i++) { 
    $x = rand(0, strlen($chars) -1); 
    $verify .= $chars{$x}; 
  } 
  return $verify; 
} 


if ( isset($_POST['submit']) )
{
// handle the form

  $message = NULL; // create empty new variable


  // check for a first name
    if ( empty($_POST['first_name']) )
    {
      $fn = FALSE;
      $message .= ' - first name';
    }
    else
    {
      $fn = $_POST['first_name'];
    }	



  // check for a last name
    if ( empty($_POST['last_name']) )
    {
      $ln = FALSE;
  $message .= ' - last name';
    }  
    else
    {
      $ln = $_POST['last_name'];
    }	


  // check for an email address
    if ( empty($_POST['email']) )
    {
      $e = FALSE;
  $message .= ' - email address';
    }
//validate email address
elseif(!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", $_POST['email']))
{
  $e = FALSE;
  $message .= ' - a valid email address';
} 
    else
    {
      $e = $_POST['email'];
    }

  // check for a phone number !!!!!!! still needs validation !!!!!!!!
    if ( empty($_POST['phone']) )
    {
      $p = FALSE;
  $message .= ' - phone number';
    } 
    else
    {
      $p = $_POST['phone'];
    }

  // check for service type
  // if url is appended with ?service=... 
  if (isset($_GET['service'] ))
    {
      $st = $_GET['service'];  //$st was $test in the example above
    }
  else if (empty($_POST['service_type'] ))
    {
      $st = FALSE;
  $message .= ' - type of service';
    }
    else
    {
      $st = $_POST['service_type'];
    }	

    $ap = $_POST['alt_phone'];
    $a1 = $_POST['address1'];
$a2 = $_POST['address2'];
$cty = $_POST['city'];
$zip = $_POST['zipcode'];
$c = $_POST['comment'];
$mon = $_POST['monday'];
$tue  = $_POST['tuesday'];
$wed = $_POST['wednesday'];
$thur =$_POST['thursday'];
$fri = $_POST['friday'];
$sat = $_POST['saturday'];
$when = $_POST['urgency'];
    



  // if everything is ok
    if ($fn && $ln && $e && $st && $p)
    {
    
   // Create mail message and send email

// make body of message from info received by form
$body = "This is a request to schedule a(n) $st from $fn $ln 
         \n phone- $p 
	 \n phone 2- $ap
	 \n email- $e
	 \n $a1
	 \n $a2
	 \n $cty
	 \n $zip 
	 \n\n $fn has requested that the appointment be scheduled $when during one of the following times-
	 \n $mon
	 \n $tue
	 \n $wed
	 \n $thur
	 \n $fri
	 \n $sat
	 \n\nproblems and comments-
	 \n $c";

//create short email message for text notification
$short_body = "$fn $ln is requesting service.  Check your email for details. $p";		 


//send messages 
mail("blank@blank.com, blank@blank.com", "Client request for service from mysite.com", $body, "From:automatic@mysite.com"); 
mail("1234567890@message.blank.com, 1234567890@message.blank.com", "service request", $short_body, "From:automatic@mysite.com");

$finished = TRUE;
if(isset($finished))  // if the form is submitted redirect 
{
echo  "<meta http-equiv='refresh' content='0;URL=http://www.mysite.com/service_submitted.html'>";
} 
//echo "Your Request for Service has been submitted.  We will contact you shortly. Thank you.";



	    exit();
      }
   				
    
    }

// End of main "submit" conditional
?> 




<!---- Start Form ----------->
<?php 
/*----This is where the echo $st; statement doesn't work properly----*/
?>
<h1>Request Service  <?php echo $_GET['service']; echo $st; ?></h1>
<link rel="stylesheet" type="text/css" href="form.css" /> 
<form action="<?php echo $url ?>" method="post">
<?php // print error message if there is one
  if (isset($message))
  {
    echo '<p class="red" style="border: none;">Please correct the red high lighted errors below and re-submit your service request</p>'; /*-------. $message;  ---*/
  }
  else
  {
    echo '<p>Please Complete this form to request service.  Required information is marked <em>*</em></p>';
  }
?>
<fieldset><legend>Type of Service Requested</legend>
    <ul>
  <li>
    <label for="service_type">Select Your Service <em>*</em></label>
	<select name="service_type" <?php if (isset($st) && $st == FALSE ) echo 'class="red"'; ?>>
	  <option value="">Please Select one</option>
          <option value="ac repair" <?php if ( $st == "ac repair" ) echo 'selected="selected"' ?>>Air Conditioner Repair</option>
          <option value="furnace repair" <?php if ( $st == "furnace repair" ) echo 'selected="selected"' ?>>Furnace Repair</option>
          <option value="heat pump repair" <?php if ( $st == "heat pump repair" ) echo 'selected="selected"' ?>>Heat Pump Repair</option>
	  <option value="duct repair" <?php if ( $st == "duct repair" ) echo 'selected="selected"' ?>>Duct Repair</option>
          <option value="ac tune up" <?php if ( $st == "ac tune up" ) echo 'selected="selected"' ?>>Performance Plus Air Conditioning Tune-up</option>
	  <option value="furnace tune up" <?php if ( $st == "furnace tune up" ) echo 'selected="selected"' ?>>Performance Plus Furnace Tune-up</option>
          <option value="maintenance" <?php if ( $st == "maintenance" ) echo 'selected="selected"' ?>>Annual System Maintenance</option>
        </select>
  </li>
</ul>
  </fieldset>
  <fieldset><legend>Contact Information</legend>
  <ul>
    <li>
  <label for="first_name">First Name <em>*</em></label>
  <input name="first_name" value="<?php if ( isset($_POST['first_name']) ) echo $_POST['first_name']; ?>" <?php if (isset($fn) && $fn == FALSE ) echo 'class="red"'; ?> />
</li>
<li>
  <label for="last_name">Last Name <em>*</em></label>
  <input name="last_name" value="<?php if ( isset($_POST['last_name']) ) echo $_POST['last_name']; ?>" <?php if (isset($ln) && $ln == FALSE ) echo 'class="red"'; ?>  />
</li>
<li>
  <label for="address1">Address 1</label>
  <input name="address1" value="<?php if ( isset($_POST['address1']) ) echo $_POST['address1']; ?>" />
</li>
<li>
  <label for="address2">Address 2</label>
  <input name="address2" value="<?php if ( isset($_POST['address2']) ) echo $_POST['address2']; ?>" />
</li>
<li>
  <label for="city">City</label>
  <input name="city" value="<?php if ( isset($_POST['city']) ) echo $_POST['city']; ?>" />
</li>
<li>
  <label for="zipcode">Zipcode</label>
  <input name="zipcode" width="40px" value="<?php if ( isset($_POST['zipcode']) ) echo $_POST['zipcode']; ?>" />
</li>
<li>
  <label for="phone">Phone Number <em>*</em></label>
  <input name="phone" value="<?php if ( isset($_POST['phone']) ) echo $_POST['phone']; ?>" <?php if (isset($p) && $p == FALSE ) echo 'class="red"'; ?> />
</li>
<li>
  <label for="alt_phone">Alternate Phone</label>
  <input name="altPhone" width="40px" value="<?php if ( isset($_POST['altPhone']) ) echo $_POST['altPhone']; ?>" />
</li>
<li>
  <label for="email">Email Address <em>*</em></label>
  <input name="email" value="<?php if ( isset($_POST['email']) ) echo $_POST['email']; ?>" <?php if (isset($e) && $e == FALSE ) echo 'class="red"'; ?>  />
</li>
<li>
  <label for="confirm_email">Confirm Email <em>*</em></label>
  <input name="confirm_email" width="40px" />
</li>
  </ul>  
    <div class="info-wrapper">
        <div class="info-title">
    No Obligation
  </div>
  <div class="info-text">
            We will contact you before scheduling your service.
  </div>
     </div>
    <div class="info-wrapper">
  <div class="info-title">
    Privacy Notice
  </div>
  <div class="info-text">
            All information submitted to Climax Heating & A/C, LLC is kept private.
    Your personal information will never be sold to or exchanged with anyone.
  </div>	
    </div>  
  </fieldset>
  <fieldset><legend>Explanation/Comments</legend>
    <ul>
  <li>
	<textarea rows="10" cols="36"  name="comment"><?php if ( isset($c) ) echo $c; ?></textarea>
  </li>
</ul>
    <div class="info-wrapper">
  <div class="info-title">
    Symptoms
  </div>
  <div class="info-text">
        Please explain the type of problem(s) you are experiencing with your comfort system.
	You may also add any additional comments here.
  </div>	
</div>
  </fieldset> 
    <fieldset><legend>When Are You Available?</legend>
    <ul>
  <li>
    <label for="monday">Monday</label>
	<select name="monday">
          <option value="">Select Time</option>
	  <option value="all day Monday" <?php if ( $mon == "all day Monday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Monday morning" <?php if ( $mon == "Monday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Monday after noon" <?php if ( $mon == "Monday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Monday evening" <?php if ( $mon == "Monday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>
  <li>
    <label for="tuesday">Tuesday</label>
	<select name="tuesday">
          <option value="">Select Time</option>
	  <option value="all day Tuesday" <?php if ( $tue == "all day Tuesday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Tuesday morning" <?php if ( $tue == "Tuesday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Tuesday after noon" <?php if ( $tue == "Tuesday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Tuesday evening" <?php if ( $tue == "Tuesday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>
  <li>
    <label for="wednesday">Wednesday</label>
	<select name="wednesday">
          <option value="">Select Time</option>
	  <option value="all day Wednesday" <?php if ( $wed == "all day Wednesday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Wednesday morning" <?php if ( $wed == "Wednesday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Wednesday after noon" <?php if ( $wed == "Wednesday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Wednesday evening" <?php if ( $wed == "Wednesday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>
  <li>
    <label for="thursday">Thursday</label>
	<select name="thursday">
          <option value="">Select Time</option>
	  <option value="all day Thursday" <?php if ( $thur == "all day Thursday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Thursday morning" <?php if ( $thur == "Thursday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Thursday after noon" <?php if ( $thur == "Thursday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Thursday evening" <?php if ( $thur == "Thursday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>
  <li>
    <label for="friday">Friday</label>
	<select name="friday">
          <option value="">Select Time</option>
	  <option value="all day Friday" <?php if ( $fri == "all day Friday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Friday morning" <?php if ( $fri == "Friday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Friday after noon" <?php if ( $fri == "Friday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Friday evening" <?php if ( $fri == "Friday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>
  <li>
    <label for="saturday">Saturday</label>
	<select name="saturday">
          <option value="">Select Time</option>
	  <option value="all day Saturday" <?php if ( $sat == "all day Saturday" ) echo 'selected="selected"' ?>>Any Time</option>
	  <option value="Saturday morning"  <?php if ( $sat == "Saturday morning" ) echo 'selected="selected"' ?>>Morning</option>
          <option value="Saturday after noon" <?php if ( $sat == "Saturday after noon" ) echo 'selected="selected"' ?>>After Noon</option>
          <option value="Saturday evening" <?php if ( $sat == "Saturday evening" ) echo 'selected="selected"' ?>>Evening</option>
        </select>
  </li>  
</ul>
    <div class="info-wrapper">
  <div class="info-title">
    When Are You Available?
  </div>
  <div class="info-text">
        Choose as many days and times as possible. We will call you to confirm your appointment.
  </div>	
</div>
<ul class="radio">
  <li>
	<input type="radio" name="urgency" value="this week" <?php if ( $when == "this week" ) echo 'checked="checked"' ?>/> This Week
  </li>	
  <li>
	<input type="radio" name="urgency" value="next week" <?php if ( $when == "next week" ) echo 'checked="checked"' ?> /> Next Week
  </li>
  <li>	
	<input type="radio" name="urgency" value="in two weeks" class="radio" <?php if ( $when == "in two weeks" ) echo 'checked="checked"' ?> /> Two Weeks 
  </li>
  <li>	
	<input type="radio" name="urgency" value="any time - not urgent" class="radio" <?php if ( $when == "any time - not urgent" ) echo 'checked="checked"' ?> /> Not Urgent 
  </li>
</ul>	
  </fieldset>
  <input name="submit" type="submit" value="Send" /> 
</form>

<!---- End Form ------------->

 

Where url is http://www.mysite.com/service.html?service=furnace%20repair

You have got to be kidding  :o

 

Your code that is setting $st to a value is inside of a conditional statement that is only true when a form was used to submit data -

 

if ( isset($_POST['submit']) )

 

That has nothing to do with you using a URL to request the posted code.

We give out sarcasm freely when people post two lines of code as being the actual relevant code that is not working and they expect someone else to be able to tell them why what they just posted does not work.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.