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=\"john@company.com\" />
	  </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
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="john@company.com" />
			 </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
Share on other sites

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.