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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing parameters to a subform

Status
Not open for further replies.

Elmserv

Programmer
Sep 25, 2004
72
GB
I am creating an invoice form in php I have a button on the bottom that can add a new line by calling itself with a parameter invscreen.php?lines=x

I have no trouble working out the lines and creating a multi line invoice.

As you enter the form the SESSION variables are created but what I can't do is get the input from the form into these session variables.

Don't forget this is entirely a PHP script there is no HTML

I was considering calling a sub form and using the post method but I have several buttons on the bottom.


Richard

 
Well its a matter of getting the Form information from the method variable and assiging it to the sessions.

Code:
$someformvalue=$_POST['someformelement'];
[green]\\Maybe validate the data from the form[/green]
session_start();
$_SESSION['mysessionvar']=$someformvalue;

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
If my button "Add line" is used to call a prog newline.php the $_POST variables are not visible in the newline.php.

Rich

 
I don't understand, you have a form that submits to newline.php the POST variables should be there, unless you are not using the POST method, are you suing the GET method?

If that's not what you are doing can you explain a bit further?





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for replying

I have three buttons on the bottom of form

New Line

Recalculate

Create Invoice (and print)

I could put a radio button and a submit, but this is getting me annoyed & I want to no how to do it.

I see something similar in PHPmyadmin but the code is not available to me


Rich
 
Buttons as in <input type=button> or Buttons as in <input type=submit>?

If you are using 3 submit buttons. then its a simple matter of testing which one is present in the processing script.

If they are normal buttons, they don't submit by themselves, they are commonly used in conjunction with Javascript to submit to a particular location.

Each button would call a JS function to alter the Action part of the form they are related to.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
unfortunatly I have no knowledge of javascript so I will go to plan b and set up 3 radio buttons with a submit button

Thanks for your help


Richard
 
If my button "Add line" is used to call a prog newline.php the $_POST variables are not visible in the newline.php.

that's because you need to wrap the whole form in <form> tags INCLUDING the addline button. send the form to the same php file (the action tag) whatever button is pressed. call all the buttons submit but give them different values.

your script then decides what action to take:

if (isset($_POST['submit'])) {

//possible values are:
// new line
// create invoice
// Recalculate

switch ($_POST['submit']){

case "New Line":
//do the new line processing and reoutput the invoice
break;
case "Create Invoice":
//do the invoice creation
break;
case "Recalculate":
//recalculate the invoice
break;
} //end the switch statement

}
[/code]
 
Jpadie was kind enough to exemplify what I said.
"If you are using 3 submit buttons. then its a simple matter of testing which one is present in the processing script."









----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I have cracked it thanks to you lot. I have used 3 submit buttons and the isset function tells me which one has been pressed.

I think "($_POST['submit'])" this bit of code might also tell me which button has been pressed. (I will investigate)

I didn't know you could have multiple submit buttons & I hadn't thought of that method.

Many thanks to all for your help

Richard
 
$_POST['submit'] is just a variable. If you try to assign it to something say $myvar you'll get an error if it is not set.

[blue]isset()[/blue] is the correct way of checking which one was set.
Code:
<form...>
<input type="submit" name="Operation1" value="do Operation 1">
<input type="submit" name="Operation2" value="do Operation 2">
<input type="submit" name="Operation3" value="do Operation 3">
</form>
Which ever one is pressed to submit the form, will create a variable $_POST['Operation[red]X[/red]'];

Code:
if(isset($_POST['Operation1'])){
[green]\\do something if the first button was pressed[/green]
}

if(isset($_POST['Operation2'])){
[green]\\do something if the second button was pressed[/green]
}
if(isset($_POST['Operation3'])){
[green]\\do something if the third button was pressed[/green]
}

Of curse they can be named whatever you want, and just check for those names.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
why not just name them the same thing and test the received value?
 
That works also, but it can get pretty messy, if you have a value like:
"Press here to perform calculations on the values entered" or something like that, it tends to get more difficult to check the string exactly, and if you decide to change whatever the button says you'll have to go in and change your checking code as well.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
agreed. i work on laptops with screen-estate limitations. a button with more than one word would be like a bathroom with a sofa in it: a luxurious waste of space!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top