Richard Lynch wrote:
I always go for the "one form" system, because otherwise you have double the work to do (opening two files) every little change, and invariably one of the forms drifts out of sync when (not if, when) you forget to change the other form and...
Thanks, Robert. I think this is the best way too. As the app I'm working on is still in development no doubt the form will be changing a few times.
Assigning data to the form mostly consists of using the VALUE= attribute in HTML tags, except TEXTAREA where it goes between opening/closing tag.
Basic logic flow:
<?php if (...){ //Detect some indicator that you want a "new_record" $query = "insert ..."; $record_id = mysql_insert_id(...); } else{ //initialize all fields to blanks: $name = ''; $address = ''; }
$record_id = isset($record_id) ? $record_id : $_REQUEST['record_id']; if (...){ //detect some indicator that you want to "update" a reocrd $query = "update ..."; }
$query = "select ... where id = $record_id"; ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> //form data here </form>
Yes, you display the form again with the data to edit, right after an insert.
That's by DESIGN, since it will help catch "ooops!" on data entry by re-confirming with the user what they just did. Better data entry is good.
Thanks for that code. It looks good.
I'm using Pear QuickForm (Pear DB for database) to create the forms, passing it to a Smarty template. I'm just a bit stumped as to how to get the data into Quickform.
Snippet of field creation:
$form->addElement('text', 'year', 'Year:');
Leonie
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php