Results 1 to 13 of 13
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    This should be simple, but I can't find a way to do it.

    I've got a page which receives POST data and does some stuff with it. Ordinarily it displays a form, and when the user submits the form it transfers to another page via the ACTION attribute. Very straightforward.

    In certain cases the page discovers that its form is inapplicable, and it needs to transfer to another page (not the same other page), sending POST data, without displaying a form first. How do I do that?

    I thought I could do this by "displaying" a form with no submit button and all hidden fields, but that just got the browser confused.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Would it work to send a 302 code to the browser, i.e., would that cause the browser to resubmit to the new URL? For PHP, see PHP: header - Manual (scroll down to the "second special case").

    == Edit ==

    I may have misread your post. If the page on the server is determining that another "action" page should be used, see above.

    If the page containing the form is determining this, e.g., in a JavaScript validation routine, you can change the action URL before the form submits.

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    I looked at the description of header and the description of 302 that it referred to. I didn't understand it completely because the description of 302 was written in RFC speak, but it seems to me that 302 is not suited to this case.

    As I understand it, 302 means, in effect, "Browser, repeat your last request, but this time only, send it to such-and-such a URL." What data is going to accompany the request? Presumably the same data that accompanied the preceding one, which would be wrong. The page has to be able to specify what data to send, just as it would if it displayed a form and the user clicked Submit.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    The page has to be able to specify what data to send, just as it would if it displayed a form and the user clicked Submit.
    Okay, then you were on the right track using JavaScript. You either could doctor up the form the user filled out, or you could have a second, hidden form, in the page, use JavaScript to copy the values from the form the user filled to the second form, then submit the second form and cancel the submit on the first form. Doctoring would be easier, and the page to which you're posting will simply ignore fields it doesn't need.

  5. #5
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    There's a misunderstanding here, because I'm not using Javascript -- everything I'm concerned with here is happening on the server.

    Apart from that, I don't really understand anything you said. Maybe that's because I have very little experience with Javascript (and getting it would be a distraction from the problems I'm dealing with right now). If it's not relevant, leave it aside. If it is, please explain some more. I understand the concept of a hidden form, but I don't see how to submit it. The only way I know to submit a form is to click a button.

    BTW, I've solved the problem another way. It's an awkward way, though, and I'd like to learn the "right way" for next time.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    I understand the concept of a hidden form, but I don't see how to submit it. The only way I know to submit a form is to click a button.
    You can add an event handler to your <form> tag called onsubmit which calls a script to examine the contents of your form and take action. The most common action would be to stop the submit process because there is an error in the input. This saves the user a round trip to the server, although of course it is not a substitute for server-side validation.

    Quote Originally Posted by jsachs177 View Post
    BTW, I've solved the problem another way. It's an awkward way, though, and I'd like to learn the "right way" for next time.
    Is it possible to design the form so that you don't need two of them, or the user always fills out the right one? That seems best if possible.

  7. #7
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    You can add an event handler to your <form> tag called onsubmit...
    There's some kind of disconnect here. According to the documentation I checked, "onsubmit is a scripting event that occurs when the user attempts to submit the form..." But the problem here is how to make the page submit the form itself -- not what happens when the form is submitted. (With no submit button, and indeed no visible elements at all, the user can't "attempt to submit the form.")

    Is it possible to design the form so that you don't need two of them, or the user always fills out the right one?
    I don't want to go into all the design details, but... the short answer is, that wouldn't even be meaningful. For example, toward the end of the process the user edits a database record, and the changes may or may not make the record a duplicate. If it does, the user must be told and allowed to edit the page again (with another form). If it doesn't, the database is updated and the process ends without another form. This simply isn't a case where one form will do the job.

    The requirement seems so simple that I was embarrassed about starting the thread. Apparently it's not as simple as it seems, but there must be a way to do it.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    There's some kind of disconnect here.
    Yes, I want you to edit the first page so it can handle all necessary submissions, and you want to edit the second page so that it can simulate a user form submission if the second page determines that it should not have received the form submission. Does that help explain my comments?

  9. #9
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    Yes, I want you to edit the first page so it can handle all necessary submissions... Does that help explain my comments?
    It does. It doesn't answer the question, though.

    I appreciate that you're trying to guide me toward an approach that you consider superior, but it's not clear to me how that approach could be made to work at all.

    Perhaps if I describe a simple but analogous process, the problem will be clearer. Imagine a process for requesting a service for which the site debits the user's prepaid account. The process looks like this:

    Code:
    Display form A ( the user enters the request for the service);
     if (user's account balance < cost of service)
     	Display form B (the user adds funds to the account);
     Display form C (the user answers a questionnaire about the service);
    This process requires the capability I want: the page for displaying form B determines whether funds need to be added, and if not, transfers control to form C without displaying form B first.

    As I understand it, you'd suggest that forms A and B be combined, so that the user is prompted to add funds whether that is necessary or not. I can't imagine a way to do that without creating massive confusion. Maybe form A+B would include helpful hints like, "If your account balance is at least as great as the cost of the service you're going to select, you can ignore the second half of this form... and if you don't already know the cost of the service, too bad!"

    I hope that makes it clearer why I'm asking this question.

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    I hope that makes it clearer why I'm asking this question.
    That's not at all the scenario I had in mind.

    I believe most applications handle this by receiving and storing the "Form A" information in session variables and then checking the account status. If the account is sufficient, the application would then process the order. If the account is insufficient, the application would set a flag to process the order later upon satisfactory completion of "Form B". You could think of this as A-to-C vs. A-to-B-to-C.

    I don't have any code like this, but it seems very analogous to a shopping cart application that lets you choose between saved information or new information (e.g., shipping address, payment method).

  11. #11
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    Yes, it's clear now what you meant. I gather that I would use header() to perform the actual load of the new page.

    This is a useful technique, and I thank you for it. If I had had it when I started this thread, though, I probably would still have chosen the kludge I used. The problem is that sessions, as I understand it, require the use of cookies, and this site site was designed to work without cookies. The client understands that virtually all web commerce sites use cookies these days, but nevertheless believes that they would pose technical problems and/or drive away some potential customers. Researching and evaluating that issue is way beyond what I've been asked to do, and it wouldn't make sense for a site that is just being patched up to work until it can be replaced.

    I'm still puzzled that this apparently simple requirement has opened such a can of worms, but I'm ready to move on.

    At this point I'm much more concerned about the problem in the other thread I started, concerning magic quotes. If you could take a look at that one and make suggestions, I'd be grateful.

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by jsachs177 View Post
    The problem is that sessions, as I understand it, require the use of cookies, and this site site was designed to work without cookies.
    The "cookieless" approach is to include a session identifier in the URL or a hidden field in the form. You may have seen either or both of these techniques used on some sites that were not conducting sensitive business.

  13. #13
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jsachs177 View Post
    Yes, it's clear now what you meant. I gather that I would use header() to perform the actual load of the new page.

    This is a useful technique, and I thank you for it. If I had had it when I started this thread, though, I probably would still have chosen the kludge I used. The problem is that sessions, as I understand it, require the use of cookies, and this site site was designed to work without cookies. The client understands that virtually all web commerce sites use cookies these days, but nevertheless believes that they would pose technical problems and/or drive away some potential customers. Researching and evaluating that issue is way beyond what I've been asked to do, and it wouldn't make sense for a site that is just being patched up to work until it can be replaced.

    I'm still puzzled that this apparently simple requirement has opened such a can of worms, but I'm ready to move on.

    At this point I'm much more concerned about the problem in the other thread I started, concerning magic quotes. If you could take a look at that one and make suggestions, I'd be grateful.
    can you not send the submitted data to a processing page that takes the data and, using a simple Select Case routine, transfers the user to Form A or B, depending? I do this all the time. the user doesn't know they passed thru the processing page; you can preserve form field across multiple pages several ways without resorting to cookies. I don't know what technology you are using, so there's some differences in syntax depending.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •