Jump to content
Larry Ullman's Book Forums

Resubmitting A Form


Recommended Posts

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

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

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

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

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...