Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Form Syntax For Variables (How To)

Posted on 2015-01-31
2
Medium Priority
?
40 Views
Last Modified: 2015-02-17
I am building a website and using the CMS Expressionengine.  I am building a form within a module and it is being displayed on a web page

My Function queries a database table and brings back a list of states.  The states are included within a Select / options dropdown .  What I am not clear on how to do is to make the <option> loop with the state name, so I have 500 <option> choices.

My Website Form: (My issue is on line 15)
{exp:states:stateids form="yes"}
<div class="quote-cont">               
	<div class="index-plug-content">
		<span class="content-white-med">
		Insurance for Bicycles
		</span>
	</div>
	<div class="quote-title-cont">
		<span class="quote-title">Get a QUICK QUOTE</span>
	</div><div class="bike-value">
		<input type="text" name="bike_value" id="bike_value" value="<?php if(isset($_POST['bike_value'])) {echo $_POST['bike_value'];} else {echo 'Bike Value';} ?>"  onfocus="this.value='';" />
	</div><div class="bike-state">
		<select name="bike_state" id="bike_state">
			<div><option value="" style="display:none">Choose State</option></div>
<option name="bike_state" class="option-center" value="{state_fee}">{state_name}</option>
//  I need the above line to loop  //
			
		</select>
	</div><div class="email-value">
		<input type="text" name="email_value" id="email_value" value="<?php if(isset($_POST['email_value'])) {echo $_POST['email_value'];} else {echo 'Email Address';} ?>" onfocus="this.value='';" />
	</div><div class="quote-submit">
		<input class="submit" type="submit" name="submit" id="submit" value="Generate Custom Quote" />
		<input type="hidden" name="get_quote" value="TRUE" />
	</div>
</div>	
{/exp:states:stateids}

Open in new window


My Function; (My issue here is on line 23 - 26 )
	public function stateids()	
	{
	//  Initiate return Data
		$tagdata = $this->EE->TMPL->tagdata;
		
	
	
	//  Show Form
		$form = (($this->EE->TMPL->fetch_param("form") == "yes"));
	
	
	//  Grab all state Data from DB
	
		$state_name = array();	
		$state_fee = array();
		
		$query = $this->EE->db->select('state, pd_base_rate')
			->from('state_rates')
			->get();
			
		foreach ($query->result() AS $row)
			{
				$vars[] = array (
				'state' => $row->state,
				'state_fee' => $row->pd_base_rate	
				);
// The above line, I am creating the variable but I need to include: 
// $state = '<option name="bike_state" class="option-center" value="{state_fee}">'.$state_name.'</option>';
			}
	//  Parse Tagdata
		$tagdata = $this->EE->TMPL->parse_variables($tagdata, $vars); 		

Open in new window

I have created the variable but I need to create the <option> tag also; <option name="bike_state" class="option-center" value="{state_fee}">'.$state_name.'</option>';
Something like that.

Any help will be appreciated.
0
Comment
Question by:rgranlund
[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
2 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 40582113
I think you're trying way too hard.
foreach ($query->result() AS $row)
			{
echo '<option name="bike_state" class="option-center" value="'.$row->pd_base_rate.'" >'.$row->state.'</option>';
			}

Open in new window

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 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