post input fields withou form tag or regular submit button?
Posted: Wed May 26, 2010 9:42 am
Hi,
I have a form that posts back to it's self and includes the form with the php vars. This works great for posting form data without redirecting the page.
However, now I'm trying to just post 4 particular fields in the form without actually submitting the form. It opens a popup and populates a new form for entering data based on what is in those 4 fields on the original form.
The below code works perfectly in that it submits the form var and then is able to echo it in a popup.
Ideally, the user would enter customer info and a bunch of other stuff, but when it comes to this one section with 4 parts they just enter the quantity and click on the "add part numbers" button. Then the popup comes up with another form populated based on the quantity that was entered in the main form. Then the user continues to fill in other data and then submits the entire form.
All is good accept you can't have a form inside a form. Other than that, the code below is good.
So my question is, How can I send those 4 fields to my testVars.php page without having them in a form tag?
Thanks for any suggestions.
Here's a quick sample code.
testPage.php:
testVars.php:
testPopup.php:
I have a form that posts back to it's self and includes the form with the php vars. This works great for posting form data without redirecting the page.
However, now I'm trying to just post 4 particular fields in the form without actually submitting the form. It opens a popup and populates a new form for entering data based on what is in those 4 fields on the original form.
The below code works perfectly in that it submits the form var and then is able to echo it in a popup.
Ideally, the user would enter customer info and a bunch of other stuff, but when it comes to this one section with 4 parts they just enter the quantity and click on the "add part numbers" button. Then the popup comes up with another form populated based on the quantity that was entered in the main form. Then the user continues to fill in other data and then submits the entire form.
All is good accept you can't have a form inside a form. Other than that, the code below is good.
So my question is, How can I send those 4 fields to my testVars.php page without having them in a form tag?
Thanks for any suggestions.
Here's a quick sample code.
testPage.php:
Code: Select all
<?php
include 'testVars.php';
?>
<html>
<head><title>page</title>
<script type="text/javascript">
// pop-up and submit function so they can both be called from submit button at the same time
var newWin = null;
function closeWin(){
if (newWin != null){
if(!newWin.closed)
newWin.close();
}
}
function popUp() {
closeWin();
var strURL = "popup.php";
var strType = 'elastic';
var strHeight = '400';
var strWidth = '275';
var strOptions="";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
newWin = window.open(strURL, 'newWin', strOptions);
newWin.focus();
}
function submitForm()
{
document.forms["myform"].submit();
}
</script>
</head>
<body>
<!--need outer form here-->
<!--several fields here not needed till final submit button-->
<form id="myform" action="page.php" method="POST">
<input type="text" name="myVar" size="25" maxlength="25"></input>
</form>
<input type="button" value="add part numbers" onclick="submitForm();popUp();"></input>
<!--more fields for final submit-->
<!--closing form tag and submit button for rest of form-->
</body>
</html>
Code: Select all
<?php
session_start();
?>
<?php
/*retrieved from form "page.php"*/
$thisVar = $_POST['myVar'];
/*session variable to pass over to popup.php*/
/*including this file in both "page.php" and "popup.php" didn't work
so I'm using http_session_vars*/
$HTTP_SESSION_VARS['formdata'] = $thisVar;
/*collect the rest of the form vars when final submit*/
?>Code: Select all
<?php
session_start();
/*retrieving data from the session variable*/
/*can create shorter session var or use "$SESSIONS" in real scenario
for easier coding*/
$newVar = $HTTP_SESSION_VARS['formdata'];
echo $newVar;
?>