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

Passing Form Field Values to PHP Page

Status
Not open for further replies.

ridgedale

IS-IT--Management
Sep 26, 2007
9
GB
I wonder if anyone could explain how I pass the field values in my request form to the PHP processor page. My doSubmit() function is as follows:

function doSubmit() {
self.focus() #Not sure whether I need this line!
window.location='<pathtoprocessor/page.php>'
}

When I click on the Submit button the error page is shown and seems to indicate that fields have not been filled in when, in fact, they have.

Any help with this would be appreciated. Thanks in advance.
 
What's the form's method? What are you using on the PHP page to get the values? Are the form element names the same as the variable names you attempt to get the values from on the PHP page?

Your question provided very little/no useful information.

Lee
 
Thanks for your replies, cLFlaVA and trollacious.

In answer to the first response, if I didn't have to use rollover image buttons there wouldn't be a problem as a standard html submit works fine, but that is not an option.

If I replace the javascript submit button code:

<a href="javascript:doSubmit();"
onmouseover="switchImage('submit', 'submit5')"
onmouseout="switchImage('submit', 'submit6')">

<img src="images/btn_submit4.jpg"
width="64" height="22" name="submit" border="0" alt="Submit Button">

</a>

with standard html submit button code:

<input type="submit" name="Submit" value="Submit">

the form data is passed to the php processing page and an email is correctly sent to the email address required containing all the information from the form fields as expected.

I believe it's because I need to pass the form field values through the doSubmit() function that the problem is occurring. The doSubmit() function is correctly raising the php processing page but there is nothing in the function:

function doSubmit() {
self.focus() #Not sure whether I need this line!
window.location='<pathtoprocessor/page.php>'
}

that passes the field values on to php processing page.

The name values being passed are:

Excerpt from the php processing page:

$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$jobtitle = $_POST['jobtitle'];
$cmp_org = $_POST['cmp_org'];
$talk = $_POST['talk'];
$email = $_POST['email'];

Please feel free to correct me if I am mistaken. I'd appreciate it if you or anyone else might be able to point out where I am going wrong.

Thanks again.
 
You're not actually submitting the form with the doSubmit() function, you're just changing the page. Try this for your submit button WITHOUT the <a href> tags you used:

Code:
<input type="image" src="images/btn_submit4.jpg" 
 width="64" height="22" name="submitbutton" border="0" alt="Submit Button"onmouseover="switchImage('submit', 'submit5')" 
onmouseout="switchImage('submit', 'submit6')">

If you name an input on a form "submit", you won't be able to use Javascript to submit the form because there will be both a method and an object with the same names. Since methods are also objects, you'll have 2 objects with the same name, causes problems.

Lee
 
Lee,

That has worked in that the form is now being processed correctly, thankyou. But unfortunately it has disabled the button rollovers! Do you have any thoughts on how I might fix this?

Thanks again.
 
Lee,

Firebug, shows the following error relating to the external .js file if this is any help:

document
has no properties
switchImage("submit", "submit5")rollover.js (line 27)
onmouseover(mouseover clientX=0, clientY=0)sbx_request.php (line 1)
[Break on this error] document
.src = eval(imgObjName + ".src");

Thanks again.
 
You really need to start figuring SOME things out for your self. The name of the image input has changed, and it is no longer an image, but an input. You need to either change your switchImage() function (which I'd guess is for images only) or hardcode the swap into the input. I'll show you one example of hardcoding the swap into the input and you should figure out the other one yourself.

Code:
<input type="image" src="images/btn_submit4.jpg" 
 width="64" height="22" name="submitbutton" border="0" alt="Submit Button" onmouseover="this.src=submit5.src;">

Lee
 
Lee,

In the end, I found a solution that just required an edit of the doSubmit() function:

function doSubmit()
{
document.forms["TheForm"].submit();
}

That did the trick and I didn't need to change anything else.

Thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top