Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 buttons on one form 3

Status
Not open for further replies.

thumbelina

Programmer
Jun 4, 2001
58
CA
I have a form for updating employee information. The employee names are listed in a dropdown box so that you can pick out a name, then there is a command button that lets you retrive the information that's stored on the name that you picked and display it in the text boxes on the form. Then I have a submit button that will let you make changes to these text boxes and save the changes. I'm worried that hitting one button that will run both pieces of code, because I have been putting the code right in with the html. I don't have any code to post because I'm not sure where to start, but If I can solve the problem with the 2 buttons I can figure out the queries. Thanks:)
 
Hi Thumbelina (tiny little thing) (sorry - have kids),

I don't often see websites that do that. Usually you have a drop down or a list of employees and you select the employee you want to edit. Selecting the employee will then bring you to another page where you can make your changes with a submit button. That submit button code will bring the user back to the page where they can select the employees again.

Now, those two pages could look exactly the same, the only change is that the submit button 'moves'.

DjangMan
 
Hi DjangMan <is ok I love kids>

Ok one more question on this one. I have never been able to get variables to pass from one page to another, and I've never figured out why it wouldn't work. Do you have any advice on that one?

Thumbelina
 
hi

u can pass variables via hidden fields in form
ie
echo &quot;<input type=hidden name=name value=$name>&quot;;
etc

regards
spookie
 
Would you explain the use of that a little more fully please. (echo &quot;<input type=hidden name=name value=$name>&quot;;) i mean it makes sense but I'm still not sure how hidden fields are going to get passed to the next page. or for that matter how i'm going to get the query result into the fields. (haven't figured out how to deal with a returned query yet)
 
hi thumbelina
inside ur form tag with the other variables u can also send hidden fields which dont appear on the browser.
eg
<form action=&quot;something.php&quot; method=post>
<input type=text name=firstname >
<input type=text name=lastname>
<input type=hidden name=status value=member>
</form>

now in something.php these u can get the firstname and the lastname entered by the user in variables $firstname and $lastname directly.and the variable $status will contain value &quot;member&quot;
so u can send query like
select * from tablename where firstname='$firstname' AND lastname='$lastname' AND status = '$status'


hope that will help u

spookie
 
how does putting the information into hidden fields get it passed to a different page. I'm sorry I just don't understand this at all.
 
Hi Thumbelina,

When you call a PHP script from a form that has a hidden variable, that form variable becomes a variable in your script. That gets passed when you click your submit button.

Then, when you are generating the output of the script results you can simply echo out another:

<input type=hidden name=status value=member>

but your value parameter may have a different value.

In short you are placing your variable in a page within a form so you can read it in your PHP script.

Now....

If you need to retain that value across pages that you weren't planning to use forms on you still could use a form that has a [NEXT >] button. It would really be a submit button that would go to a script that PHP directs to another page. Ugh. What a mess. X-)

If that doesn't help - perhaps you could describe the reason you want to pass the variable around?

DjangMan
 
All of this relates back to my orginal question. If i'm going to seperate the two buttons into 2 pages then I will need to send variables from one page to another, only I can't get it to work. I've only been working with php and mysql (that's the database the site is linked to) for about 6 weeks now, so some of the more complex functions and stuff like that are giving me trouble. I hope this clears up a bit of the confusion on what I'm looking for. I really apperacite your help.

Thumbelina
 
hi thumelina
honestly i havnt understood ur problem completely
anyway u can have number of submit buttons on your form
so if one button displays the details and other saves the changes u can do something like this..
<form action....>

<input type=submit name=submit value=display_details>
<input type=submit name=submit value=save_changes>



now in ur php code u can check which button is clicked by

if($submit == &quot;display_details&quot;) {
display details..
}

if($submit == &quot;save_changes&quot;) {
update record..
}


hope that will help u

regards
spookie


 
spookie I think you should add this one to the FAQ section.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top