Custom PHP Dropdown - Get user selected value and option |
2/6/2025 10:12:56 PM |
PHPRunner General questions | |
C
chandoshi authorDevClub member
I have a custom PHP dropdown programed as a code snippet. it display multiple columns from a single database records as rows of items to select from. The code works perfectly. $str = "<select style='width: 150px; display: inline-block;' class='form-control' onchange=\'window.location.href=this.options[this.selectedIndex].value;\'>"; |
|
C
|
copper21 2/7/2025 |
Use ChatGPT: // Check if the form was submitted // Generate dropdown // Select values from the database while ($data = db_fetch_array($rs)) { $str .= "</select>"; // Display the selected contact for verification You can take the last part out to display it if you want...but you should be able to use the session variable "$_SESSION['selected_contact']" in your app. |
C
|
chandoshi authorDevClub member 2/9/2025 |
Thanks for getting back to me. The solution work perfectly. Just 2 questions for clarification.
|
C
|
copper21 2/10/2025 |
According to Chat GPT, the reason why the [ if $SERVER["REQUESTMETHOD"] == "POST "] is before the dropdown is because you want to capture and process the submitted form data before rending and updating the dropdown. Now to get the name selected along with the ID, do you want the ID to show in the dropdown too? |
![]() |
Peer Plaut 2/10/2025 |
copper21 - |
![]() |
fhumanes 2/11/2025 |
Hello, In my problem, I need to facilitate a selector field with all the backup files in a directory and the user has to select one, to apply it to recovery. In this case, the field information is not even based on the database. What have I done: 1.- I define a view of one of the tables of the application that what serves me is for Phprunner to facilitate the access insurance issues and the "frame" of the application, the rest of the fields, I eliminate it in the Design page 2.- Defined a "snippet", to build the HTML that I need for the selector field, and access the directory to collect the files that exists and puts it as values of it. 3.- I define a 3-states button, where:
The codes are:
<?php $option=''; // Recoger los ficheros de export de base de datos, más recientes.| Leave only the 5 recent database export. $pref_filebackup = 'Videoclub'; chdir(DIR.'/backup_files/'); $arrFiles = glob($pref_file_backup.'*'); rsort($arrFiles); // Ordenar de mayor a menor for ($i = 0; $i < count($arrFiles); $i++) { $html = <<< EOT
// Put your code here. console.log('Fichero de carga: ',params["file_restore"]); return true;
$file_restore = $params["file_restore"]; // Fichero del backup include "backup/restore.php"; $result["message_user"] = $message_user; - After Javascript console.log('Inicia la 3 fase'); if (confirm("El mensaje del Restore es: " + msg_user) == true) {
Greetings, |