This is a discussion on 2 Forms within the PHP Language forums, part of the PHP Programming Forums category; I was handed a voting form that the company has used in previous years, for updating. The first page is ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I was handed a voting form that the company has used in previous years,
for updating. The first page is a form, asking for name, business name, title and email address(twice for verification). The form gets posted to a verfication PHP script that checks that the email addresses match and that the email address isn't already in the database. If there is a problem, it sends you back to the first form; if everything is okay it sends you on to the second form. The second form is the actual voting form. At the top of the screen, the customer's information is displayed for them, using PHP variables. So that name, business name, and title are at the top. Customer fills out the form and clicks submit. The form forwards to a PHP script for inserting the data into MySQL. This is where the problem comes in. Everything but the name, title and email address gets written to the database. I have checked my SQL query and it is find. My working theory right now is that the second form erases all variables from the first form, as for as the system is concerned. Here is a line of code from the second form: <form method="POST" action="check.php?email=<?php echo $email ?>"> It looks like the origional program was passing email in the URL which would explain why email works but the name, business name and title don't. I think the origional coder knew the issue. I am looking for confirmation of my belief that only one set of variables can exist at a time, from a form for any given method. If that is true, how do I pass multiple variables in the URL above? I tried seperating them with commas or ?. |
|
|||
|
Jerim79 wrote: > I was handed a voting form that the company has used in previous years, > for updating. The first page is a form, asking for name, business name, > title and email address(twice for verification). The form gets posted > to a verfication PHP script that checks that the email addresses match > and that the email address isn't already in the database. If there is a > problem, it sends you back to the first form; if everything is okay it > sends you on to the second form. > > The second form is the actual voting form. At the top of the screen, > the customer's information is displayed for them, using PHP variables. > So that name, business name, and title are at the top. Customer fills > out the form and clicks submit. The form forwards to a PHP script for > inserting the data into MySQL. This is where the problem comes in. > Everything but the name, title and email address gets written to the > database. I have checked my SQL query and it is find. My working theory > right now is that the second form erases all variables from the first > form, as for as the system is concerned. Here is a line of code from > the second form: > > <form method="POST" action="check.php?email=<?php echo $email ?>"> > > It looks like the origional program was passing email in the URL which > would explain why email works but the name, business name and title > don't. I think the origional coder knew the issue. I am looking for > confirmation of my belief that only one set of variables can exist at a > time, from a form for any given method. If that is true, how do I pass > multiple variables in the URL above? I tried seperating them with > commas or ?. I was able to find that the & symbol is the seperator between multiple variables. It is working now. I still haven't found confirmation that only one set of POST or GET variables can exist at one time. If this is true, I wonder how the problem is handled at larger companies where multiple POST forms could make up a site. Certainly they don't resort to URL GET as I could see how the strings could be quite long in some cases. |
|
|||
|
Jerim79 wrote:
> My working theory > right now is that the second form erases all variables from the first > form, as for as the system is concerned. Indeed, this is the case. A form submission is a *one-time-only* action. Whatever form fields exist are passed to the next page, afterwhich they no longer exist. Submitting that second form passes on the second form's data, but none of the first. > <form method="POST" action="check.php?email=<?php echo $email ?>"> > Eww. This just looks like a bad idea. Typically, to have forms span multiple submissions, you need to propogate the form fields, but not like this. The easiest way is to use hidden form fields. IE, something like: <input type="hidden" name="name" value="<?php echo $_POST['name'] ?>"> You give each piece of data you want to propogate it's own hidden element, that way this data gets included along with the next form submission. |
|
|||
|
Moot wrote: > Jerim79 wrote: > > My working theory > > right now is that the second form erases all variables from the first > > form, as for as the system is concerned. > > Indeed, this is the case. A form submission is a *one-time-only* > action. Whatever form fields exist are passed to the next page, > afterwhich they no longer exist. Submitting that second form passes on > the second form's data, but none of the first. > > > <form method="POST" action="check.php?email=<?php echo $email ?>"> > > > > Eww. This just looks like a bad idea. Typically, to have forms span > multiple submissions, you need to propogate the form fields, but not > like this. The easiest way is to use hidden form fields. IE, something > like: > <input type="hidden" name="name" value="<?php echo $_POST['name'] ?>"> > > You give each piece of data you want to propogate it's own hidden > element, that way this data gets included along with the next form > submission. Thank you. I had thought about hidden buttons, but wasn't sure if that was the way to go. I will go back and do it the way you suggested. |