The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
[SOLVED] Has anyone gotten server-side validation to work? - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: API (https://forums.formtools.org/forumdisplay.php?fid=17) +--- Thread: [SOLVED] Has anyone gotten server-side validation to work? (/showthread.php?tid=243) Pages:
1
2
|
[SOLVED] Has anyone gotten server-side validation to work? - sergiozambrano - Aug 14th, 2009 If you have a working sample, PLEASE send it out! I've seen the latest tutorials working, but they use rsv (javascript) on the client side. I've read a few post with the same problem than mine: an empty form is returned if validation fails (post here http://forums.formtools.org/showthread.php?tid=196&highlight=valid) I'll test the whole page you send me in my server and I'll tart replacing small bites. This is driving me crazy and I have to track down the error. Thanks. RE: Has anyone gotten server-side validation to work? - Ben - Aug 16th, 2009 Hey Sergio, Unless we can locate & fix the problem where process.php is failing to set the error info in sessions, server-side validation won't work on your server. See my previous post about contacting me with your login info. - Ben RE: Has anyone gotten server-side validation to work? - sergiozambrano - Aug 16th, 2009 Ben, I've sent you the login info to your email. I'd save you the time, I know you must be very busy. Just send me an example of server-side validation php with the API and I'll change the FT path and form number to test it in my server! Thanks. RE: Has anyone gotten server-side validation to work? - cssmw - Aug 17th, 2009 The only way I have got server side validation to work on my system without returning an empty form if validation fails is to use $_POST instead of $fields as given in the online examples. e.g. PHP Code: <?=htmlspecialchars($_POST["fullname"])?> instead of... PHP Code: <?=htmlspecialchars($fields["fullname"])?> [FIXED] Solution from Ben Keen - sergiozambrano - Aug 18th, 2009 Ben has been kind enough to try the error right in my form, so here's his message plus a few edits. Replace your if(empty($errors)) statement by the following: (replace your button's name attribute, next page finlename with yours) PHP Code: if (empty($errors)) { There were two situations that weren't working: (1) When the PHP validation failed (e.g. invalid email address), $fields wasn't being updated with the latest & greatest form field content. So these lines take care of that: else $fields = array_merge($fields, $_POST); (2) when the user entered CAPTCHA incorrectly, again the $fields variable wasn't being updated with the latest content. So what I did was merge the content stored in $_SESSIONS (which IS up to date) with $fields. This ensures $fields has the latest content for displaying in the page. $fields = array_merge($fields, $_SESSION["form_tools_form"]); In terms of a long term fix, I'm going to have to think some more about this. Issue (1) is something that will have to be handled in the form code, so that won't change. But for (2), it seems like ft_api_process_form() should return an updated version of $fields when the user fails CAPTCHA. So expect an update to the API at some point that makes that step a little simpler (don't worry, though - it will be compatible with this code so you can upgrade in safety). RE: [FIXED] Solution from Ben Keen - spenny - Aug 21st, 2009 I've also run into this problem but have been unable to solve it using the above solution. I added the line PHP Code: else but the page still loses all the form data when server side validation fails. Can anyone help? RE: [FIXED] Solution from Ben Keen - cssmw - Aug 21st, 2009 I have now managed to get server-side validation to work using Ben's solution. Integrated into my code (which only creates database entries when the form is submitted) Ben's solution looks like this... PHP Code: <?php And just above the form... PHP Code: <?php The only difference is that I have used the following PHP in the form... PHP Code: <?php echo htmlspecialchars(@$fields['fm_name']); ?> ...instead of as in the online examples... PHP Code: <?=htmlspecialchars(@$fields['fm_name'])?> RE: [FIXED] Solution from Ben Keen - sergiozambrano - Aug 21st, 2009 (Aug 21st, 2009, 12:21 AM)spenny Wrote: I've also run into this problem but have been unable to solve it using the above solution. I think it wasn't matter of just "adding" the line to your code. The code we had before had the IFs conditionals nested different. Make sure you added the other line I posted and also the braces are balanced the same (resulting in a diferent nesting of conditionals) RE: [SOLVED] Has anyone gotten server-side validation to work? - msaz87 - Sep 14th, 2009 Has anyone run into trouble keeping the values in drop downs? When I try to put in the documented code for mine: PHP Code: <select name="Played_Before" class="registration"> It spits back the following on loading the page: PHP Code: <select name="Played_Before" class="registration"> If you run a test of the form, it clears the values back to normal and if you try it a second time, it works... but obviously I need it to work the first time around. The page being worked on is: http://fasports.com/az/phx/mondays_new.php -- but it might be changing as I'm still playing around with it Any help is appreciated... thanks! RE: [SOLVED] Has anyone gotten server-side validation to work? - Ben - Sep 18th, 2009 Hi msaz87, Ah - this is due to the PHP error notification level. I have it cranked up really high so that I can hear about all problems like this. You can fix it in two ways: 1. In your config.php file, add the following line: PHP Code: $g_default_error_reporting = 1; That will tell it to only report genuine errors, not notices (minor, potential problems) like the ones you described. 2. In your form, add a "@" symbol before referencing the $fields variables. This suppresses minor warnings/notifications, like undefined indexes. For example: Code: <select name="Played_Before" class="registration"> Hope this helps! - Ben |