Hello, everyone,
I’m trying to validate a set of text inputs that have the same name, as well as their associated SELECT that all have a different same name. (Does that make sense?)
For example, the user has the option of choosing how many entries they want to enter. So, if a user chooses to enter 3 entries, the relevant DOM would look like:
<input type="text" name="ncode" class="n required"> <select name="nsize" class="s required"><option value="Small">Small</option><option value="Large">Large</option></select><br />
<input type="text" name="ncode" class="n required"> <select name="nsize" class="s required"><option value="Small">Small</option><option value="Large">Large</option></select><br />
<input type="text" name="ncode" class="n required"> <select name="nsize" class="s required"><option value="Small">Small</option><option value="Large">Large</option></select><br />
As far as checking the value of each, I’m not experiencing any issues. However, I’m running across an issue if one of the text fields is left blank.
So, if a user enters a code into the first and last fields, but leaves the middle field blank, it throws the index off.
123456
234567
345678
… will result in 123456,234567,345678
.
123456
345678
… will result in 123456,345678
.
Is there a way to force the empty text input to register so the second example will result in 123456,,345678
?
V/r,
Basic form processing will not pass the object through if it’s empty, so I’d guess you’d need to check the different form fields and place a space there.
I’d consider looking at re-tooling the form, though. That seems a VERY confusing way to handle something like that. Seems to me having unique names might be a better option, even if it means a little more detailed form processing on the back side.
So, even doing something like appending []
to the name wouldn’t change anything? Force an empty value into the object value?
I could append a number to the end of each name, I suppose, but it would mean more work, I think, on the backend.
V/r,
PaulOB
April 6, 2015, 7:17pm
4
If you created an array then the result would look like this I believe.
Array
(
[ncode] => Array
(
[0] => 111
[1] =>
[2] => 333
)
[nsize] => Array
(
[0] => Small
[1] => Small
[2] => Small
)
)
The second input was blank.
Using code like this.
<form method="post" action="dump.php">
<input type="text" name="ncode[]" class="n required">
<select name="nsize[]" class="s required">
<option value="Small">Small</option>
<option value="Large">Large</option>
</select>
<br />
<input type="text" name="ncode[]" class="n required">
<select name="nsize[]" class="s required">
<option value="Small">Small</option>
<option value="Large">Large</option>
</select>
<br />
<input type="text" name="ncode[]" class="n required">
<select name="nsize[]" class="s required">
<option value="Small">Small</option>
<option value="Large">Large</option>
</select>
<br />
<input type="submit">
</form>
Not sure if that helps you as that’s about the limit of my knowledge .
1 Like
I gave it a shot… nope… even with ncode[]
as the name, no difference.
This is the first time I’ve ever needed to work with something like this that isn’t radio or checkboxes. Learning things, every day.
V/r,
Yeah… I went ahead and just set it so that each has a unique name/id. Slightly more work on the back end, but I’m making some semi-decent progress on the validation.
Thanks to @DaveMaxwell and @PaulOB for your input.
PaulOB
April 7, 2015, 1:50pm
7
Glad you are making progress
system
Closed
July 7, 2015, 8:56pm
8
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.