Solved

Form Syntax For Variables (How To)

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

822 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