form not submitted because FieldA...

User 345797 Photo


Registered User
48 posts

I have a form with a series of drop down fields which I dynamically generate from a mysql database. I am trying to write the fields to a mysql table. When I display the form, the dropdowns have the correct information in the display. When I inspect the dropdown fields, they appear to have the correct id, value and display value in them. But when I submit the form i get:
YOUR FORM COULD NOT BE SUBMITTED FOR THE FOLLOWING REASON(S):
"Field1" DOESN'T HAVE A VALID VALUE.
repeated for each of the drop down fields.
Each dropdown field has the following format (as taken from the inspect of the element in google chrome):
"<option id="item131_select_1NoProgram" value="NoProgram"> No Program</option>
<option id="item131_select_11" value="JUDOSR"> Judo Kinder Senior SK-Gr 1</option>
<option id="item131_select_12" value="COMPJR"> Computer Club Junior 1-3</option>

I don't understand where the invalid value is located.

Thanks for any help.

Thanks
User 187934 Photo


Senior Advisor
20,271 posts

Hi Janice,

How did you set up the dropdown originally in the form builder?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 345797 Photo


Registered User
48 posts

Below is the code. There are 20 drop down fields which I want initialised right from the start so I can't use an onchange event for example. I figured putting it in the $(window).load event would make sure that it was initialised when the page is first displayed. Note that currently I have async: false as part of the ajax call, which has been deprecated. I needed to put that in because only the last drop down ended up with values. Once I put that in, all the drop down fields ended up with values. I am at the moment looking at the code you had posted March 29th, 2016, since it uses pdo.

$(document).ready(function($) {
$( window ).load(function() {
var im;
var i;
//var initial_target_html = '<option value="">Please select a program</option>'; //Initial prompt for target select
var n;
var fieldId;
var selectvalue1;
var selectvalue2;
var currentname;
var currentId;
var elements = document.getElementsByTagName('select');
for (var i=0, im=elements.length; im>i; i++) {
currentname = ($(elements[i]).attr('name'));
currentId = $("*[name="+currentname+"]").attr('id');
n = currentname.indexOf("Program");
if (n > 0) {
fieldId = currentname.substr(n+7,1);
//Grab the chosen value on first select list change
if (fieldId == "1") {
selectvalue1 = "15:45";
} else {
selectvalue1 = "16:50";
}
if (currentname.substr(0,3)=="Alt") {
dayName = currentname.substr(3,3);
} else dayName=currentname.substr(0,3);
switch(dayName) {
case "Mon":
selectvalue2 = "Monday";
break;
case "Tue":
selectvalue2 = "Tuesday";
break;
case "Wed":
selectvalue2 = "Wednesday";
break;
case "Thu":
selectvalue2 = "Thursday";
break;
default:
selectvalue2 = "Friday";
}
//Display 'loading' status in the target select list
$('#'+currentId).html('<option value="">Loading...</option>');
if ((selectvalue1 != "") && (selectvalue2 != "")){
//Make AJAX request, using the selected value as the GET
$.ajax({url: '../loaddropdown.php?day='+selectvalue2+'&time='+selectvalue1+'&id='+currentId,
async: false,
success: function(output) {
if (output == "") {
alert("no return values");
} else {
output='<option id = "'+currentId+'NoProgram" value="NoProgram"> No Program</option>'+output;
$('#'+currentId).html(output);
return output;
}},
error: function (xhr, ajaxOptions, thrownError) {
alert("error "+xhr.status + " "+ thrownError);
}});
} else {
alert("Problem in finding programs. Please reload page and try again.");
$("#"+currentId).focus();
} //end of if selectvalue
} //end of if for program
} //end of for
}); //end of load
}); //end of ready


Below is the php for the loaddropdown.php

<?php
$dropdownday=$_GET['day'];
$dropdowntime=$_GET['time'];
$fieldId = $_GET['id'];
$username = "myuser";
$password = "mypassword";
$hostname = "localhost";
$DBname = "mydbname";
$n=1;

$link = mysqli_connect($hostname, $username, $password, $DBname);

/* check connection */
if (mysqli_connect_errno()) {
$message = "Error: Connect failed: " . mysqli_connect_error();
echo $message;
exit();
}

$sql = "SELECT Programs.ProgramName, ProgramSchedule.ProgramCode, ProgramSchedule.ProgramDay, ProgramSchedule.ProgramHour ";
$sql = $sql."FROM Programs INNER JOIN ProgramSchedule ON Programs.ProgramCode = ProgramSchedule.ProgramCode ";
$sql = $sql ."WHERE ProgramSchedule.ProgramDay = '".$dropdownday."' AND ";
$sql = $sql ."DATE_FORMAT(ProgramHour,'%H:%i') = '".$dropdowntime."'";

if ($result = mysqli_query($link, $sql)) {
if (is_null($row = mysqli_fetch_assoc($result))){
$message="No programs exist for ".$dropdownday." at the time ".$dropdowntime.".";
echo $message;
}else {

// $optionlist = '<option value="' . $row{'ProgramName'} . '"> '.$row{'ProgramName'}.'</option>';
$optionlist = '<option id="' . $fieldId . $n . '" value="' . $row{'ProgramCode'} . '"> '.$row{'ProgramName'}.'</option>';
$n=$n+1;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$optionlist = $optionlist. '<option id="' . $fieldId . $n . '" value="' . $row{'ProgramCode'} . '"> '.$row{'ProgramName'}.'</option>';
$n=$n+1;
//$optionlist = '<option id="' . $row{'ProgramName'} . '" value="' . $row{'ProgramName'} . '"> '.$row{'ProgramName'}.'</option>';
}
echo $optionlist;
}
mysqli_free_result($result);

}else {
$message = "Error in query: " . $sql;
echo $message;
}
?>
User 345797 Photo


Registered User
48 posts

Sorry, I realised I didn't actually answer your question. I just used a regular drop down field element with only one value. There are 20 fields and each has a unique name. i.e. MonProgram1, MonProgram2, AltMonProgram1 etc. for each day Monday - Friday. Then I created the jquery I sent you above to load each of the drop down fields with the appropriate value.
User 187934 Photo


Senior Advisor
20,271 posts

Try setting the dropdowns to required and delete all the options.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 345797 Photo


Registered User
48 posts

It won't let me delete all the options so there is one option left. I can't make it required because none of the options may be chosen.
I noticed in the posting about dynamically modifying drop downs from March 30, 2016 that Ken said that he was able to get the drop downs to dynamically load when he followed the following steps (and of course had working scripts)
1. Create the form with a dummy select
2. Dynamically modify the html file to set the options using the item id that is created (you will have to update by incrementing the field counter)
3. Dynamically modify the form.cfg rules line to reflect the change in options.

Could my problem be the form.cfg? What does he mean by reflect the change in options? Do I have to include all the option values I have generated in the form.cfg? ( have about 12 options per day)
User 345797 Photo


Registered User
48 posts

I went into the form.cfg file and all the drop down lists had lower case names i.e. monprogram1 whereas the name of the field was MonProgram1. I changed the names in the form.cfg and it accepted the record BUT it didn't write anything for the field MonProgram1 in the table. So for example, I had selected the first actual program for Monday (ace room) and the second program for the alternate Monday (computer club), but neither one of them were written to the database. All the other information was written successfully to the database.

So now there are two questions, 1) why were the names different in the form.cfg and the actual form and 2) why didn't it write the contents of the drop down.
User 187934 Photo


Senior Advisor
20,271 posts

Was the dropdown showing at submit?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 345797 Photo


Registered User
48 posts

Yes. All looks good except the drop downs don't end up in the DB.(all the other fields do, including another drop down which I am not changing programmatically). Their field names appear as columns correctly in the DB just not data.
The fields in the rules section of the form.cfg do not use the same case as in form builder. For example I have a field called StWed. In form.cfg is shows as stwed. That field updates no problem and does not show an illegal label id.

I decided that I would change the problem form fields to be the same as in the rules section of form.cfg (ie all lower case). The drop downs display correctly but NO update to the database takes place at all (not even the fields that had updated correctly)

I changed the field names back to upper case/lower case in form builder and I get an illegal Id.
"MONPROGRAM1" DOESN'T HAVE A VALID VALUE.
"TUESPROGRAM1" DOESN'T HAVE A VALID VALUE.

SO, I decided to not load up the drop downs and see if it works and it does.

SO then I loaded up the drop downs, changed the names in the rules section of form.cfg to MonProgram1 etc. and it wrote all the fields to the db but NOT the drop down fields that I created.

I also changed the names in the payment_rules section to be the same as above. Again, the form processed fine except that the drop down fields were not written to the DB.

So, it would appear that there is something in the form.cfg (or another file) which controls the write and the programmatically created fields are not being referenced.
User 187934 Photo


Senior Advisor
20,271 posts

Why don't you write your own php scripts for the form.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.