Solved

Form Syntax For Variables (How To)

Posted on 2015-01-31
2
36 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 83

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

821 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