close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Displaying validated entries and/or recordset values BUT in a dynamic drop-down menu?

Thread begun 12/04/2018 12:04 pm by Nathon Jones Web Design | Last modified 12/05/2018 1:29 pm by Ray Borduin | 899 views | 3 replies |

Nathon Jones Web Design

Displaying validated entries and/or recordset values BUT in a dynamic drop-down menu?

When adding the WA Server Validations to any form, it quickly becomes apparent that when you submit the form, and validation fails, all of your form values are wiped and the user has to start the entire form again. I'm not sure why that is, but it's the current state of play.

So, you have to manually add the ValidatedField data as the default value for every field in your form, like so:

<input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="First name" maxlength="30" value="<?php echo(ValidatedField("healthscreeningform_984","FirstName")) ?>" required>



But what if your form is populated by data from a recordset? Well, you have to double up the default value to include the ValidatedField data AND the Recordset data, like so:

<input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="First name" maxlength="30" value="<?php echo(isset($_GET['v'])?ValidatedField("healthscreeningform_984","FirstName"):$rsEDITFORM->getColumnVal("SMCformFIRST")) ?>" required>



This is incredbily time consuming to configure, but it's working.

My problem is how to handle dynamic drop-down menus? At the moment I have the option values within a repeat region, like so...

<?php
while(!$rsCOUNTRIES->atEnd()) { //dyn select
?>
<option value="<?php echo($rsCOUNTRIES->getColumnVal("SMCcountryID")); ?>"<?php if (!(strcmp($rsCOUNTRIES->getColumnVal("SMCcountryID"), (ValidatedField("healthscreeningform_984","Country"))))) {echo "selected=\"selected\"";} ?>><?php echo($rsCOUNTRIES->getColumnVal("SMCcountryNAME")); ?></option>
<?php
$rsCOUNTRIES->moveNext();
} //dyn select
$rsCOUNTRIES->moveFirst();
?>



Two things this isn't doing. It's not displaying the Country from the Recordset ($rsEDITFORM), and it's also not remembering the ValidatedField data so the Country menu is wiped blank every time validation fails.

One thing that might be complicating this is that I have a sub-dependent State field which changes depending on what the user selects from the Country drop-down.

What is wrong with my code that it's not remembering the Country selection by the user, and how do I, like my other fields, also incorporate the Recordset country and region data?

This can be viewed at:
www.sportsmedicalcertificates.com/health-screening-form.php?tab1=1

Thank you
NJ

Sign in to reply to this post

Ray BorduinWebAssist

It looks like it would work to select the country after failed validation. I'd need FTP access to debug why it isn't.

If you set the default selection in your dynamic select Server Behavior to:

<?php echo(isset($_GET['v'])?ValidatedField("healthscreeningform_984","Country"):$rsEDITFORM->getColumnVal("SMCformCOUNTRY")) ?>

Just like you do in the input elements, then it should work the same way.

I'd also strongly suggest using webassist jquery client form validation. That catches most errors before the form submits and bypasses some of the complexities involved with server validation. Server Validation is a stronger validation and good for backup.

Sign in to reply to this post
Did this help? Tips are appreciated...

Nathon Jones Web Design

Thank you Ray.

Adding that to the dynamic select Server Behaviour, for the country field, seems to have done the trick and I've added it for the various region field options too but, because when the validation fails the page effectively reloads, it's not recalling the onChange behaviour that would have been initiated on the first submission of the form by the user selecting either the US or UK - both of which call dynamic sub-dependent drop-down menus.

Thankfully it does recall the State name and displays it, when validation fails, but if you'd selected, for example, the US you would usually be shown a drop down menu of states. When validation fails, you are just shown a standard input field. It's not ideal but to change it I'd need to look at the whole onChange behaviour which is currently this:

<script>
$("#Country").change(function() {

if ( $(this).val() == 425) {
$("#RegionsUS").hide();
document.getElementById('RegionsUS').disabled = true;
$("#RegionsOTHER").hide();
document.getElementById('RegionsOTHER').disabled = true;
$("#RegionsUK").show();
document.getElementById('RegionsUK').disabled = false;
}
else if ( $(this).val() == 426) {
$("#RegionsUS").show();
document.getElementById('RegionsUS').disabled = false;
$("#RegionsOTHER").hide();
document.getElementById('RegionsOTHER').disabled = true;
$("#RegionsUK").hide();
document.getElementById('RegionsUK').disabled = true;
}
else {
$("#RegionsOTHER").show();
document.getElementById('RegionsOTHER').disabled = false;
$("#RegionsUS").hide();
document.getElementById('RegionsUS').disabled = true;
$("#RegionsUK").hide();
document.getElementById('RegionsUK').disabled = true;
}
});
</script>



Is there any way of simplifying the WA jQuery Client Form Validation? The speech bubbles aren't mobile compatible and there are simpler ways of displaying the error, for example highlighting the input field in red with a small text message below it.

Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

The bubbles should be mobile compatible. What is the issue with mobile?

You could probably just add this to the bottom of the page right before the </body> tag:

<script>
$("#Country").change();
</script>



That should call the onchange code when the page loads so the appropriate form element would show.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...