bnorcom Posted September 13, 2016 Share Posted September 13, 2016 In the 5th Ed of PHP on page xii it says Asp.Net is a server-side alternative and the next page says "they can do things PHP can't." Then on page 130 it says to "resubmit the form in different states of completeness to test the results more." In Asp.Net there is a View State where it remembers the content of fields, but to resubmit a PHP form you have to keep reentering data each time. Is there a way to sent the form back with the previous data intact by refilling the fields using JavaScript (or JQuery) after PHP validation routines have been run? I suppose that would involve PHP calling a function which would in turn call a JavaScript function which would get everything in the right sequence. Also that would involve sending the page back to the original page containing the form from the page which handled it in the first place. Sounds like this would be asking more than this book covers. On page xiii it says "PHP was written for dynamic Web page creation." It seems that dynamically recreating the form with all its formatting and tags would be a lot harder than Asp.Net just representing it from its View State. Thanks for the help. Link to comment Share on other sites More sharing options...
bnorcom Posted September 15, 2016 Author Share Posted September 15, 2016 I hadn't read about sticky forms yet. But I wonder about line 9 on page 222 which uses print '<h2> etc. It seems that if you're running a <?php program that you have to use PRINT to create a line whereas with HTML5 you could just use the tag having been statically formatted and not have to print it. For example, with the FORM in Script 8.9 apparently you don't have to use PRINT within a form. Be that as it may, in line 63 you begin using "print htmlspecialchars". That's to avoid hacking. But there are other PHP routines to validate data also. It seems they could all be put into a function instead of cramming them into one line (which really makes PHP inelegant). However, once the validating function is run you'd probably need JavaScript to getElementById to put the results in an <input> field. I was hoping there was a straightforward way to execute validation methods and then use jQuery to place the results in static HTML fields already formatted instead of printing long lines of complicated syntax which are hard to program and not very good documentation. I can only conclude that ASP.Net would be much more user friendly with its formatted page and codebehind file than PHP's cramming it all into one line and then having to print it. Link to comment Share on other sites More sharing options...
bnorcom Posted September 16, 2016 Author Share Posted September 16, 2016 After reading further and thinking about it there is server-side and client-side, the latter running on the browser. So since the former is server-side the two can't exist together as apples and oranges. The only thing I can think of is that a field can be statically defined with HTML and then an insert area made for the attribute VALUE = where a <?PHP clause could be used to provide a variable name. Then all the validation could be done beforehand and the data could be inserted just in that one spot where JavaScript would have used getElementById on the client-side. That way you could have your cake and eat it too with HTML formatting already provided and not having to be "printed" and a PHP function doing all the validation necessary resulting in that output being inserted. Link to comment Share on other sites More sharing options...
bnorcom Posted September 19, 2016 Author Share Posted September 19, 2016 Validating elsewhere and purging a field of hacks whereby creating a sanitized variable works fine. Then it can be printed after "value=" just like getElementById. However, I did discover that with PHP 5.4.9 you have to: $name = trim($_POST['name']); $x = isset($name); if ($x) etc. because this earlier version of PHP won't allow if (isset($_POST etc)) directly. Link to comment Share on other sites More sharing options...
Larry Posted September 20, 2016 Share Posted September 20, 2016 Hey! Can you confirm whether you still have a question here or not? I can't tell from reading the thread. Thanks! Link to comment Share on other sites More sharing options...
bnorcom Posted October 8, 2016 Author Share Posted October 8, 2016 The successive posts show how I was working it out step by step. The last one is simple and it works, so I would use it this way and don't have any more questions. Link to comment Share on other sites More sharing options...
Larry Posted October 11, 2016 Share Posted October 11, 2016 Cool. Thanks for letting us know and kudos for figuring it out! Link to comment Share on other sites More sharing options...
Recommended Posts