Jump to content

Echo Form Problem


dsbpac

Recommended Posts

I'm having a problem with my form not working correctly when it's in an echo function. If i paste the code in the page without the if/elseif statement it works fine. It's when I put it in echo tags? Any help would be awesome TYVM

 

<?php
$product_id = $_GET['product_id'];
if ( $product_id == "23" ) {
require_once('phpgd/index.php');  
 }
elseif ( $product_id == "24" )
 {
echo "<div class=\"preview\">
 <img src=\"phpgd/scripts/server-side.php\" width=\"400\" height=\"244\" />
   </div>
<form id=\"realtime-form\" action=\"#\" method=\"post\">
<fieldset>
  <legend>Business Card Builder Form</legend>
  <ol>
   <li class=\"left\">
    <fieldset>
	 <legend class=\"accessibility\">Company Information</legend>
	 <ol>
	  <li>
	   <label for=\"company-name\">Company name</label>
	   <input type=\"text\" id=\"company-name\" name=\"companyName\" value=\"Company Name\" />
	  </li>
	  <li>
	   <label for=\"company-slogan\">Company slogan:</label>
	   <input type=\"text\" id=\"company-slogan\" name=\"companySlogan\" value=\"Company Slogan\" />
	  </li>
	  <li>
	   <label for=\"business-address\">Business address</label>
	   <textarea id=\"business-address\" name=\"businessAddress\">1234 Main Street
Suite 101
City, ST 12345</textarea>
	  </li>
	 </ol>
    </fieldset>
   </li>
   <li class=\"right\">
    <fieldset>
	 <legend class=\"accessibility\">Contact Information and Description</legend>
	 <ol>
	  <li>
	   <label for=\"full-name\">Full name</label>
	   <input type=\"text\" id=\"full-name\" name=\"fullName\" value=\"John Smith\" />
	  </li>
	  <li>
	   <label for=\"job-title\">Job title</label>
	   <input type=\"text\" id=\"job-title\" name=\"jobTitle\" value=\"Job Title\" />
	  </li>
	  <li>
	   <label for=\"primary-phone\">Primary phone</label>
	   <input type=\"text\" id=\"primary-phone\" name=\"phoneOne\" value=\"P: 954-555-1234\" />
	  </li>
	  <li>
	   <label for=\"secondary-phone\">Secondary phone</label>
	   <input type=\"text\" id=\"secondary-phone\" name=\"phoneTwo\" value=\"P: 954-555-5678\" />
	  </li>
	  <li>
	   <label for=\"email-address\">Email address</label>
	   <input type=\"text\" id=\"email-address\" name=\"emailAddress\" value=\"[email protected]\" />
	  </li>
	  <li>
	   <label for=\"web-address\">Web address</label>
	   <input type=\"text\" id=\"web-address\" name=\"siteUrl\" value=\"websiteurl.com\" />
	  </li>
	 </ol>
    </fieldset>
   </li>
  </ol>
 </fieldset>
   </form>

";
}

Link to comment
https://forums.phpfreaks.com/topic/272467-echo-form-problem/
Share on other sites

Please note, that if you are comparing numbers, you should cast the $product_id as an (int) and remove the quotes around the comparison number E.G. "24" should just be 24.

 

Try this:

<?PHP

if(!isSet($_GET['product_id'])) {
//### You could declare a default product id number?
//### For now we're showing a default error message
echo 'You have not declared a product ID number.';
exit;

} else {
//### Assign and cast product id
$product_id = (int)$_GET['product_id'];

}

if($product_id == 23 ) {
//### Include file
include('phpgd/index.php');

} else if($product_id == 24) {
//### Display HTML Form otherwise
echo <<<HTML_FORM
<div class="preview">
	 <img src="phpgd/scripts/server-side.php" width="400" height="244" />
 </div>
<form id="realtime-form" action="#" method="post">
<fieldset>
	 <legend>Business Card Builder Form</legend>
	 <ol>
	 <li class="left">
		 <fieldset>
			 <legend class="accessibility">Company Information</legend>
			 <ol>
			 <li>
			 <label for="company-name">Company name</label>
			 <input type="text" id="company-name" name="companyName" value="Company Name" />
			 </li>
			 <li>
			 <label for="company-slogan">Company slogan:</label>
			 <input type="text" id="company-slogan" name="companySlogan" value="Company Slogan" />
			 </li>
			 <li>
			 <label for="business-address">Business address</label>
			 <textarea id="business-address" name="businessAddress">1234 Main Street
Suite 101
City, ST 12345</textarea>
			 </li>
			 </ol>
		 </fieldset>
	 </li>
	 <li class="right">
		 <fieldset>
			 <legend class="accessibility">Contact Information and Description</legend>
			 <ol>
			 <li>
			 <label for="full-name">Full name</label>
			 <input type="text" id="full-name" name="fullName" value="John Smith" />
			 </li>
			 <li>
			 <label for="job-title">Job title</label>
			 <input type="text" id="job-title" name="jobTitle" value="Job Title" />
			 </li>
			 <li>
			 <label for="primary-phone">Primary phone</label>
			 <input type="text" id="primary-phone" name="phoneOne" value="P: 954-555-1234" />
			 </li>
			 <li>
			 <label for="secondary-phone">Secondary phone</label>
			 <input type="text" id="secondary-phone" name="phoneTwo" value="P: 954-555-5678" />
			 </li>
			 <li>
			 <label for="email-address">Email address</label>
			 <input type="text" id="email-address" name="emailAddress" value="[email protected]" />
			 </li>
			 <li>
			 <label for="web-address">Web address</label>
			 <input type="text" id="web-address" name="siteUrl" value="websiteurl.com" />
			 </li>
			 </ol>
		 </fieldset>
	 </li>
	 </ol>
	 </fieldset>
 </form>
HTML_FORM;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/272467-echo-form-problem/#findComment-1401952
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.