Solved

Form Syntax For Variables (How To)

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

738 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