Solved

Form Syntax For Variables (How To)

Posted on 2015-01-31
2
33 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
2 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now