Jump to content

Edit Form Output


Go to solution Solved by Psycho,

Recommended Posts

Honestly, i dont even know where to start here... or if its even possible the way i am envisioning it BUT

 

I currently output form information from a MySQL DB - its pretty large - about 75 fields and i format them in a zebra-striped table for easy reading.  Heres a small example

while ($row = mysqli_fetch_array($result)) {

				       echo "<tr>";
                                       echo "<td>Provider</td>";
                                       echo "<td>";
                                       echo $row['assignedcounselor'];
                                       echo "</td></tr>";                                        
                                      
                                       echo "<tr>";
                                       echo "<td>Patient Name (" . $row['childadult'];
                                       echo ")</td>";
                                       echo "<td>";
                                       echo $row['firstname'] ." ". $row['lastname'];
                                       echo "</td></tr>";
                                       
                                       and so on....

}

  I want my receptionist to be able to click on a small icon next to any field and just be able to edit the contents and the field updates in mysql upon clicking another button (save icon). Something sorta like the scren mockup below.

 

scr_Mock.png

 

 

Is something like this do-able in PHP or will i need to add javascript.. Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/286554-edit-form-output/
Share on other sites

  • Solution

OK, are you only wanting the user to edit individual fields or the entire record? Allowing edit of the entire record would actually be easier.

 

You could allow them to edit individual fields by clicking a button and, I assume, you want it to all happen on the current page. If that's the case, then you'll need to use a combination of JavaScript and PHP (i.e. AJAX). It would take quite a lot to explain everything, but I can break it down to the main features.

 

1. When generating the output, create input fields for the data - but set them to readonly and apply a style so they are visibly readonly (e.g. I typically use a grey background). So, instead of

 

echo "<td>{$row['assignedcounselor']}</td>\n";

Use something like this

 

echo "<td><input type='text' id='assignedcounselor' name='assignedcounselor' value='{$row['assignedcounselor']}</td>\n";

 

2. Additionally, when outputting the records create an edit icon/button for each field as well as a save icon/button. These will call JS functions to initiate the edit/save processes. The function calls will need to include the field name or ID. The save option should be initially disabled.

 

3. Create a JS function to enable editing on a field. This will take the ID/Name passed to the function. Then it will change the style properties of the field so it is not readonly and is displayed as a normal input field. The save button should be enabled and you could also change the edit button to be a cancel button at this point.

 

4. Create a JS function for the save option. That function should take the ID of the field passed to reference the value in the field. It would then make an AJAX call to a PHP page to update the selected value. You would need to pass the Record ID, the name of the field and the value of the field. The response should either be a TRUE (for success) or an error message if there were validation errors. The JS function would either set the field back to the readonly state (if success) or display the error message.

Edited by Psycho
Link to comment
https://forums.phpfreaks.com/topic/286554-edit-form-output/#findComment-1470799
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.