Contextual Option to add entry to database (hit enter once, hit enter twice within 4 seconds)

gisvpn
gisvpn used Ask the Experts™
on
Hi,

I was looking for some guidance on the approach to a specific user experience and how people would approach it or if someone has done something like this already.

I have a simple PHP script that enters a value from a text box into the database when the 'add' button is clicked or the user hits enter after entering a value (script below).

What I would like to do is allow a user to hit the enter key when they add their record (as it works below), but if the user were to hit the enter key again, within 4 seconds, it would bring up the full record that they could edit. It is because sometimes the user will only add the one value, but sometimes they will add the one value and also want to view and edit some other fields for that record - how would others approach this from a scripting perspective and also side topic on the User Experience side; are there better ways to do this?




$form = "<form action='./dash_hit46.php' method='post'>" .PHP_EOL;
$form .="<input type='text' id='newadd' name='newadd' placeholder='e.g. x'>" .PHP_EOL;
$form .="<input type='submit' value='add' name='add'>" .PHP_EOL;
$form .="</form>";


if ($_POST['add']){
	
	$newadd = $_POST['newadd'];
		if ($newadd){

		
		// Check connection
if ($conn_task2->connect_error) {
    die("Connection failed: " . $conn_task2->connect_error);
} 

$sql = "INSERT INTO main (tsk_name, tsk_person, tsk_user_link)
VALUES ('$newadd', 'me', '$UID')";

if ($conn_task2->query($sql) === TRUE) {
    echo "New record created successfully $form";
} else {
    echo "Error: " . $sql . "<br>" . $conn_task2->error;
}

$conn_task2->close();
		
		
		
		
	}	
				else
						echo "nothing entered. $form";
}
else

		echo "$form";

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
I ended up writing a script that would pull the last record the user entered if they tried to submit an empty value in the form (i.e., they pressed enter twice - once to add the record and a second time to pull the full record back up.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial