Page 1 of 1

Newbie- Problem with Submit; Please Help

Posted: Mon Nov 14, 2005 6:09 pm
by patti
Hi. I have just started using PHP and created a form for users to select a combination of 3 products. But, I have two problems with the form.

Problem 1: the user has to submit twice to get the form to post. I view the page source and the form action is set just fine so I do not understand why the form won't submit.

Problem 2: After the form finally gets processed, if the user decides to go back to the form to add more products, the form action never gets reset to $_SERVER['PHP_SELF'].

Never mind- solved my problem!

Posted: Mon Nov 14, 2005 6:23 pm
by blacksnday
Your Form start is messed up.. change:

Code: Select all

echo "<FORM method=\"POST\" name=\"prods\" action=\""; print $action; echo "\">";
to

Code: Select all

echo "<FORM method=\"POST\" name=\"prods\" action=\"$action\">
you dont need to stop the echo to use a php variable.

For a person who has dealt heavily with forms and php in the
past two months... your form code scares me!
LOL... that would be a nightmare to edit :(

Same for the rest of the form, you can use ONE echo for whole form and remove all the
print stuff...


edit to add:

You can also move all the

Code: Select all

if(isset($_POST['rthqty'])) print $rthqty;
to be either all above or below form, that way the form can be purely
one echo without breaks. unless you need them there for display reasons

Not sure if this is correct, but couldnt you do something like

Code: Select all

if(isset($_POST['rthqty'])$rtest = $rthqty)
then in the form for the value of the field:

Code: Select all

<td><input type=\"text\" size=\"3\" name=\"prods[product1]\" value=\"$rtest\">
if that works then you could clean up the form and be way easier to debug later.

Code: Select all

$baseamt=$_POST['baseamt']; 
 if(isset($_POST['rthqty'])$rtest = $rthqty)
 
echo "
	<FORM method=\"POST\" name=\"prods\" action=\"$action\"> 
    <table cellspacing =\"0\" cellpadding=\"4\" border=\"3\"  \>"
    <tr>
    <th> prods available</th>
    <th> Enter the Qty.</th> 
    <th> Cost<br />USD</th>
    <th> Discount %</th>
    <th> Discount Total</th>
    <th> SubTotal</th>
    </tr>
	<tr>
	<td><input type=\"hidden\" name=\"product1\" value=\"product1\" />product1</td>
	<td><input type=\"text\" size=\"3\" name=\"prods[product1]\" value=\"$rtest\"> 
";
then just continue the changes for the rest of the form

Posted: Mon Nov 14, 2005 6:42 pm
by patti
I have the action set to print right now for further testing. It doesn't seem to matter one way or another for the form to have to be submitted twice. And, yes, I have all the if(isset ...) for display reasons.

I have not been coding for months; I just started learning all of this 3 weeks ago, so I'm sure my code is not the best -

Posted: Mon Nov 14, 2005 10:01 pm
by patti
thanks everyone for your inputs and ideas. I got it solved!!