Solved

Php Html Value List Pulled from Database only Http Posting the First Word

Posted on 2014-02-05
9
906 Views
Last Modified: 2014-02-11
Hello,

I have a little php site that was created via a wizard that pulls data from a database.  On the edit records page there is a value list of shipping carriers that are pulled from the database.  A user can pick the shipping carrier.  When they click the button to submit the updates, only the first word is posted.  For example if the shipping carrier picked is "Old Dominion" - only "Old" is submitted.  This appears to be the code in the php file that deals with this value list:

<td class="field_data">
<?php $fieldName = 'Ship Via';?>
<?php $fieldValue = $record->getField('Ship Via', 0) ; ?>
<select class="fieldinput" name="<?php echo getFieldFormName($fieldName, 0, $record, true, 'POPUPLIST', 'text');?>" id="shipvia">
<?php $menuOptions = getMenu($layout->getValueListTwoFields('Shipping Carriers', (isset($master_record)) 
  ? $master_record->getRecordId() 
  : $record->getRecordId()), $fieldValue, $fieldName, 'text', $submitDateOrder);
  if ($fieldValue == "") {
    $selected = "selected";
  } 
  else {
    $selected = "";
  } 
  if (($cgi->get('menuSelectedFound') == false) && ($selected == "")) {
    $menuOptions = "<option value='$fieldValue' selected>$fieldValue</option>".$menuOptions; 
  } 
  $menuOptions .= "<option value='' $selected></option>";
  echo $menuOptions;
?>
  </select>
</td>

Open in new window


The following is the html code section created:
<option value=AAA Cooper >AAA Cooper</option>
<option value=ABF >ABF</option>
<option value=ALG >ALG</option>
<option value=Canada Post >Canada Post</option>
<option value=Central Freight >Central Freight</option>
<option value=CH Robinson >CH Robinson</option>
<option value=Consolidated Freightways >Consolidated Freightways</option>
<option value=Conway >Conway</option>
<option value=CTII >CTII</option>
<option value=Custom Companies >Custom Companies</option>
<option value=Custom Company >Custom Company</option>
<option value=Dayton >Dayton</option>
<option value=Dayton Freight >Dayton Freight</option>
<option value=DHL >DHL</option>
<option value=Dohrn >Dohrn</option>
<option value=Dugan >Dugan</option>
<option value=Eagle >Eagle</option>
<option value=Echo >Echo</option>
<option value=Emery >Emery</option>
<option value=Estes >Estes</option>
<option value=Estes Express >Estes Express</option>
<option value=FEDERAL EXPRESS >FEDERAL EXPRESS</option>
<option value=FedEx  selected>FedEx</option>
<option value=FedExpress >FedExpress</option>
<option value=Forward Air >Forward Air</option>
<option value=GI Trucking >GI Trucking</option>
<option value=Hercules >Hercules</option>
<option value=JP Express >JP Express</option>
<option value=Lee Jennings >Lee Jennings</option>
<option value=NEMF >NEMF</option>
<option value=Oak Harbor >Oak Harbor</option>
<option value=Old Dominion >Old Dominion</option>
<option value=Pilot Delivers >Pilot Delivers</option>
<option value=Pitt Ohio >Pitt Ohio</option>
<option value=Pitt Ohio Express >Pitt Ohio Express</option>
<option value=PJAX >PJAX</option>
<option value=Purolator >Purolator</option>
<option value=R&amp;L >R&amp;L</option>
<option value=Roadtex >Roadtex</option>
<option value=Roadway >Roadway</option>
<option value=Saia >Saia</option>
<option value=SEFL >SEFL</option>
<option value=SEKO >SEKO</option>
<option value=Southeastern Freight >Southeastern Freight</option>
<option value=Southwestern Motor >Southwestern Motor</option>
<option value=Sweeney Transportation >Sweeney Transportation</option>
<option value=Team World Wide >Team World Wide</option>
<option value=Unishippers >Unishippers</option>
<option value=UPS >UPS</option>
<option value=USF Holland >USF Holland</option>
<option value=USPS >USPS</option>
<option value=Vitran >Vitran</option>
<option value=Ward Trucking >Ward Trucking</option>
<option value=Wilson >Wilson</option>
<option value=Yellow Freight >Yellow Freight</option>
<option value=YRC >YRC</option>
<option value='' ></option>

Open in new window

I am assuming the problem is that the option values are not being place in quotes.  Can you tell me how to update the html php code so that it places that option value in quotes if that is the solution?

Thank you,
Shawn
0
Comment
Question by:smower
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 75 total points
ID: 39837853
I don't see any way that your code could generate that result.  There must be something else going on.  And please use the "code" section for posting code.  Makes it much easier to read and it include line numbers so we can discuss specific things.
if (($cgi->get('menuSelectedFound') == false) && ($selected == "")) {
   $menuOptions = "<option value='$fieldValue' selected>$fieldValue</option>".$menuOptions;
    }
$menuOptions .= "<option value='' $selected></option>";

Open in new window

0
 

Author Comment

by:smower
ID: 39837939
Yes, there is more to the code but this is the section that creates the drop down value list of shipping carriers. I need to learn the code display. How do I change this line of code so that it puts quotes around the drop down list values in the HTML code?

$menuOptions = "<option value='$fieldValue' selected>$fieldValue</option>".$menuOptions;

Thank you, Shawn
0
 
LVL 57

Assisted Solution

by:Julian Hansen
Julian Hansen earned 75 total points
ID: 39838008
The problem is your values are not enclosed in quotes

For instance
<option value=AAA Cooper>AAA Cooper</option>

Should be
<option value="AAA Cooper">AAA Cooper</option>

HTML5 standards specify that all attributes should be enclosed in quotes.

Also (not part of the problem) your selected attribute should be

selected="selected"

Although the single selected is supported it is not compliant with the HTML5 standards.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39838085
But value='$fieldValue' does have single quotes which should be fine.  But they are not showing up in your results.  That's why I say that something else must be going on because the quotes are there in your code but not in your results.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 150 total points
ID: 39838148
Hi, Shawn.  You are correct in your understanding that HTML value attributes must be quoted to work correctly.  In the complex interaction between PHP and HTML, the place and effect of quotes can be confusing.  This article may help with your understanding.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12241-Quotation-Marks-in-PHP.html

If a line of PHP code says this...

echo "<option value='$x'>";

The double quotes surrounding the entire string will cause the $x variable to be substituted; the resulting string will contain the value that is contained in the $x variable.  The single quotes around $x will be present in the output.

But if a line of PHP code says this...

echo '<option value="$x">';

The single quotes surrounding the entire string will cause the entire string, including $x, to be considered a literal string and variable substitution will not occur.  The resulting string will contain, literally, $x and $x will be surrounded by the double quotes.

In the original code snippet line 15 contains this:

$menuOptions = "<option value='$fieldValue' selected>$fieldValue</option>".$menuOptions;

A careful examination of that assignment statement shows us that we are using the first pattern described here.  The outer double quotes provide for variable substitution and the interior single quotes will come through unalloyed into the HTML document.  In addition, the $menuOptions string will contain the literal string selected in every line.  Yet when we look at the generated HTML, we are shown something like this:

<option value=Old Dominion >Old Dominion</option>

There are no quotes, and the literal string selected is missing.

It follows that the PHP code you're looking at cannot possibly be the code that generated the <option> tag we're seeing here.

I don't know how to advise you beyond showing the symptoms.  You might want to discard the wizard (the code looks terribly antiquated) and just write the PHP code directly.  That way you would have some direct control over the inputs and outputs.  If you're new to PHP and want some guidance in how to get started, this article can help point you in the right direction.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0
 

Assisted Solution

by:smower
smower earned 0 total points
ID: 39839189
Ok.  I did some further testing and research and found a helper file with a line like this:

$options .= "<option value=$encodedStoredValue $selected>$encodedEachValue</option>";

so I changed it to:

$options .= "<option value='$encodedStoredValue' $selected>$encodedEachValue</option>";

and that seems to have fixed the problem.  Thank you to all for your help.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39839197
That looks much more like it!
0
 

Author Closing Comment

by:smower
ID: 39849651
That was the final code I changed to get it to work.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How difficult would it be build a cookie scanner in PHP? 21 59
Format Date 7 28
Last 4 numbers of a variable 9 21
Can't Find The Code 15 19
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question