Jump to content

[SOLVED] PHP + Javascript form values


dumdumsareyum

Recommended Posts

Not sure whether to post this in PHP or Javascript. I have a form that is being submitted when another form is submitted using javascript.

 

<form action="out_detail.php" method="post" enctype="multipart/form-data" onsubmit="javascript:submitdetail()" >

Where submitdetail looks like:
function submitdetail()
{
  document.forms.detail_form.submit();
}

 

The problem I'm having is I'm not sure how to capture the information that is submitted from the first form before the second form submits. I tried setting a session variable at the very beginning of page for the value I'm looking for:

 

if($_POST[detail_descrip])
{
$_SESSION[add_out][detail_descrip] = $_POST[detail_descrip];
}

 

but the info is not showing up in the session variable, like the page doesn't load or something in between form submissions for the value to be set?  Help please.

Link to comment
https://forums.phpfreaks.com/topic/164972-solved-php-javascript-form-values/
Share on other sites

I spot some problems with your php, but it shouldn't break it:

if($_POST[detail_descrip])
{
$_SESSION[add_out][detail_descrip] = $_POST[detail_descrip];
}

You need session_start() and make sure to use quotes around the key names (unless you defined a constant with that name). Otherwise it'll throw a notice.

<?php
session_start();
if($_POST['detail_descrip'])
{
$_SESSION['add_out']['detail_descrip'] = $_POST['detail_descrip'];
}

I do have a session start (just didn't show here) and I know that my other session variables I am setting are working when I'm not using javascript to submit a form prior to submitting the form that was clicked on. Thanks for the warning on the array keys though, it hasn't given me an issue so far but good to know.

 

I have several separate forms with submit buttons on the page, but I want one specific form submitted everytime another form on the page is submitted. So also if anyone has suggestions of another way to do this they'd be appreciated to :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.