Newbie- Problem with Submit; Please Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
patti
Forum Newbie
Posts: 3
Joined: Mon Nov 14, 2005 5:57 pm

Newbie- Problem with Submit; Please Help

Post 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!
Last edited by patti on Mon Nov 14, 2005 10:02 pm, edited 1 time in total.
User avatar
blacksnday
Forum Contributor
Posts: 252
Joined: Sat Jul 30, 2005 6:11 am
Location: bfe Ohio :(

Post 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
Last edited by blacksnday on Mon Nov 14, 2005 6:46 pm, edited 2 times in total.
patti
Forum Newbie
Posts: 3
Joined: Mon Nov 14, 2005 5:57 pm

Post 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 -
patti
Forum Newbie
Posts: 3
Joined: Mon Nov 14, 2005 5:57 pm

Post by patti »

thanks everyone for your inputs and ideas. I got it solved!!
Post Reply