Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PEAR::HTML_QuickForm Question

Status
Not open for further replies.

mrtopher

Programmer
Aug 27, 2003
34
US
I am in the process of building an application using PEAR::QuickForm and I have a question regarding how it refreshes. I have built a dual purpose form that allows people to add a value to a database on top and then all the values added in the database are displayed in a drop down box at the bottom of the form where users can remove values by selecting them.

The form is set to submit to itself and add the newly entered value into the database but every time I enter a new value it doesn’t appear in the drop down box. I have to do an extra refresh in order to get it to display and by that time the value that the user entered has been entered into the database twice.

I have two questions: first does anyone know why the value that the user entered in the form, after it is submitted, doesn’t immediately appear in the drop down box (if it is easier to see code, I can post it)? Second, when a QuickForm form is submitted to itself the values remain in the form elements after the page refreshes. How do you get the values to return blank after someone has submitted the form?

Any help is greatly appreciated.
 
Can you post the code ?

--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Code:
<?php 
/***************************************************************************
 *                                badgeAreas.php
 *                            -------------------
 *   begin                : Tuesday, May 4, 2004
 *   copyright            : (C) 2004 CM Web D&D
 *   email                : cmmonnat@myway.com
 *
 ***************************************************************************/
 
 	require_once('../../include.php');
	
	// Connect to MySQL database using values from config file
	$iniVars = parse_ini_file('../../config.ini', TRUE);
	$db = &new MySQL(
		$iniVars['Database_Settings']['host'],
		$iniVars['Database_Settings']['user'],
		$iniVars['Database_Settings']['pass'],
		$iniVars['Database_Settings']['dbname']); 
		
	$sql = "select * from bTrack_timeFrame";
	$result = $db->query($sql);
	
	while($time = $result->fetch())
		{
			$enteredTimes[$time['timeID']] = $time['time'];
		}
	
	 // Instantiate necessary classes
	$form = new HTML_QuickForm('configAdmin', 'POST', 'timeFrame.php');
	$renderer =& $form->defaultRenderer();

	
	// Add form elements
	$form->addElement('header', null, 'Add Time');
	$form->addElement('text', 'time', 'Time:', array('size' => 25, 'maxlength' => 5));
	$form->addElement('submit', null, 'Add Time');
	$form->addElement('header', null, 'Current Times');
	$form->addElement('select', 'availableTimes', 'Current Times:', $enteredTimes);
	$form->addElement('button', null, 'Delete Time');
	
	if($form->validate())
		{
			$time = $form->exportValue('time');
			
			$sql = "insert into bTrack_timeFrame(timeID, time) values('', '$time')";
			$db->query($sql);
			if(!$db->isError())
				echo 'Time added.';
			else
				echo 'Time not added';
		}
	
	$sql = "select * from bTrack_timeFrame";
	$result = $db->query($sql);
	
	while($time = $result->fetch())
		{
			$enteredTimes[$time['timeID']] = $time['time'];
		}

	$form->display();

 ?>
 
Its difficult to point out the weak area (if any) of the code, since the code you have given here, calls various functions outside the code.
Since the value is getting inserted into the DB table, the area of inspection may be the piece of code which fetches the values from the table and put it in drop down menu.





--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top