HTML Forms

  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

Hi All

I hope someone can give me some advise.

I have the following 2 forms on one web page:

Code: [ Select ]
<form action="rdns.php" method="post">
<b><font color="#0000ff" face="verdana">Enter Domain Name e.g., mydomain.com:</b>
<br>Click <em>Lookup</em> when done</font>
<br><br>
<input type="text" name="dns" size="25" style="font-size: 14px;" />
<br><br>
<input type="submit" value="Lookup" name="Submitdns" style="font-size: 14px;"/>
<input type=reset value=Reset name="reset" style="font-size: 14px;">
</form>
  1. <form action="rdns.php" method="post">
  2. <b><font color="#0000ff" face="verdana">Enter Domain Name e.g., mydomain.com:</b>
  3. <br>Click <em>Lookup</em> when done</font>
  4. <br><br>
  5. <input type="text" name="dns" size="25" style="font-size: 14px;" />
  6. <br><br>
  7. <input type="submit" value="Lookup" name="Submitdns" style="font-size: 14px;"/>
  8. <input type=reset value=Reset name="reset" style="font-size: 14px;">
  9. </form>


and the other one;

Code: [ Select ]
<form action="rdns.php" method="post">
<b><font color="#0000ff" face="verdana">Enter An IP Address:</b>
<br>Click <em>Lookup</em> when done</font>
<br><br>
<input type="text" name="ip" size="25" style="font-size: 14px;" />
<br><br>
<input type="submit" value="Lookup" name="Submitip" style="font-size: 14px;"/>
<input type=reset value=Reset name="reset" style="font-size: 14px;">
</form>
  1. <form action="rdns.php" method="post">
  2. <b><font color="#0000ff" face="verdana">Enter An IP Address:</b>
  3. <br>Click <em>Lookup</em> when done</font>
  4. <br><br>
  5. <input type="text" name="ip" size="25" style="font-size: 14px;" />
  6. <br><br>
  7. <input type="submit" value="Lookup" name="Submitip" style="font-size: 14px;"/>
  8. <input type=reset value=Reset name="reset" style="font-size: 14px;">
  9. </form>


First I enter a value in the top form, click the submit (submitdns).
Using this value I find a few items which are then displayed.

Now I enter a value in the bottom form, click the submit (Submitip).
Using this value I find a few items which again are then displayed.

My problem is that when I submit the bottom form, all the values that where displayed by the top form disappear so that I can only see the values of the bottom form.

The same holds true if I go back to the top form.
The values from the bottom form now disappear.

What I would like to see is that all values remain, regardless of what form I submit.
It looks like it cannot be done with what I have done.

Can someone give me some advise.
Maybe use some PHP to see which submit was clicked and disable the other one from submitting at the same time.
It looks like a NULL value is being submitted by the other form when I submit a form.
I would like to prevent this.

Any help would be appreciated.

Thanks
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

It is hard to tell exactly since I have not tested anything out. My first guess would be that you using two separate forms on a page, ie:

Code: [ Select ]
<form action="rdns.php method="post">
blah blah
blah blah
</form>

<form action="rdns.php method="post">
blah blah
blah blah
</form>
  1. <form action="rdns.php method="post">
  2. blah blah
  3. blah blah
  4. </form>
  5. <form action="rdns.php method="post">
  6. blah blah
  7. blah blah
  8. </form>


When you do that and you hit submit on any of those forms, only the elements within that form I believe are passed, which is why when you submit one form, everything in the other is blank, and vice versa. What you need to do is combine all of this into one single form so that all of your values are passed.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

thanks for the reply

When I send from one form, results are displayed

Whne I send from second form, results are displayed but results from first form disappear.

Why is this happening since I am not resending first form
I would have expected results to still be visible
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

No problem. When you hit the submit on the 2nd form, only the elements within that 2nd form are passed. Everything on the first form is ignored. You need to have all of the elements within one form element if you don't want anything to be ignored.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

I still do not understand

Even if they are ignored, what about the values that had already been found and displayed in the first form

Why are they being cleared
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

They are being cleared because you are reloading the page with the values from the 2nd form sent via the POST method. All of the old values in the form would be lost unless you sent them along with the POST method too, and to do that they all have to be within the same form element.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

I think I understand now why due to the reloading which makes sense.

You state if they are all in the same form element this will not happen.

If I combine both forms into one, I will still have two submit buttons.

As you stated, since page gets reloaded, wouldn't this still clear data depending on which submit was pressed even though they are both in one form.

Maybe I still don't quite grasp this
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Any submit button inside a form would submit the form, doesn't matter. You could have 50 submit buttons -- any one of them even if named all differently would submit the same form with the same result. So all of the data within the form elements would be passed still. However, if you want the results on the reload to be different depending on what submit button was clicked, you will need to name your submit button's differently and extract that info inside your script to determine what submit button was clicked and what course of action you would want to take.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

I think I understand what you are saying.

I made one form with two submit buttons

All the caclulations are done for both submit buttons on the same page which is the action attribute.

When I enter input 1, input 2 is empty
I assume when I click submit1, it sends input 1 and empty input 2

This means I see results for input 1 and nothing for input 2

I now enter input 2 and input 1 is empty
When I click submit 2, I see results for input 2 and results I had for input 1 are gone

I need to see results for input 1 and input 2 to compare.

No matter what I do, I can't get this to happen.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

Maybe you could PM me the URL where I can see what is going on. This is all within one form element now? Are you using PHP for the calculations (ie at rdns.php), or JavaScript via the client?
  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 566
  • Loc: Fort Worth, TX

Post 3+ Months Ago

You have to manually set the values of all the fields in the form. It has nothing to do with the form being posted but with the page being re-loaded, so if you reload the page all the values will be reset.

Another way of accomplishing things without the page being reloaded is by using Ajax, so everything on the page stays the same.

So you have to do something like:

Quote:
<?php

$dns = (isset($_POST['dns'])? $_POST['dns']: null);

?>
<form action="rdns.php" method="post">
<b><font color="#0000ff" face="verdana">Enter Domain Name e.g., mydomain.com:</b>
<br>Click <em>Lookup</em> when done</font>
<br><br>
<input type="text" name="dns" size="25" style="font-size: 14px;" value="<?php echo $dns;?>"/>
<br><br>
<input type="submit" value="Lookup" name="Submitdns" style="font-size: 14px;"/>
<input type=reset value=Reset name="reset" style="font-size: 14px;">
</form>




The same for the other form:
Quote:
<?php

$ip = (isset($_POST['ip'])? $_POST['ip']: null);

?>
<form action="rdns.php" method="post">
<b><font color="#0000ff" face="verdana">Enter An IP Address:</b>
<br>Click <em>Lookup</em> when done</font>
<br><br>
<input type="text" name="ip" size="25" style="font-size: 14px;" vale="<?php echo $ip;?>"/>
<br><br>
<input type="submit" value="Lookup" name="Submitip" style="font-size: 14px;"/>
<input type=reset value=Reset name="reset" style="font-size: 14px;">
</form>
  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 566
  • Loc: Fort Worth, TX

Post 3+ Months Ago

However when you post one of the forms, only the data from the form you submit will bet sent. So you might want to consider putting everything in just one form instead of two forms, like everyone else does., or use ajax as suggested above.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

Thanks for repy

I do not quite understand your codes:

Code: [ Select ]
$dns = (isset($_POST['dns'])? $_POST['dns']: null);
$ip = (isset($_POST['ip'])? $_POST['ip']: null);
  1. $dns = (isset($_POST['dns'])? $_POST['dns']: null);
  2. $ip = (isset($_POST['ip'])? $_POST['ip']: null);


what is the ? for.

Could you please go through your code for me so I can understand better.

My intent is to have two forms.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

That PHP code is basically a shorthand for an if statement. I use it all the time as well to condense code down to a single line. For example these two are equivalent:

PHP Code: [ Select ]
$dns = (isset($_POST['dns'])? $_POST['dns']: null);


PHP Code: [ Select ]
if(isset($_POST['dns'])) {
   $dns = $_POST['dns'];
}
else {
   $dns = null;
}
  1. if(isset($_POST['dns'])) {
  2.    $dns = $_POST['dns'];
  3. }
  4. else {
  5.    $dns = null;
  6. }


Basically what happens is you first set a condition before the question mark. If when executed it turns out to be true, then it executes the part right after the question mark and before the colon. If the condition is false, then it will execute the code right after the colon.
  • wpas
  • Proficient
  • Proficient
  • User avatar
  • Posts: 327
  • Loc: Canada

Post 3+ Months Ago

Thanks for the explanation

If I understand correctly then:
If someone has pressed the submit button, the the value of $_POST['dns'] then exists.
We check then if dns value exists.
If it exists it is set to whatever value was inputed
If it doesn't exist, then it is set to null.

Could you please explain what cjxxi was trying to tell me.
The only way I know is to reload during post which wipes everything out.
I am not sure what he is saying concerning using Ajax so you do not have to load. Nothing seemed to change in my forms.

Post Information

  • Total Posts in this topic: 15 posts
  • Users browsing this forum: No registered users and 134 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.