Hi,

The question is regarding PHP and Javascript/Jquery.

I have a php page which process the form data and displays it on SUBMIT.
I need to collect that data into javascript.
how should I proceed?

//Php file

<?php 
@session_start();
$uname = $_SESSION['sessionVar'];
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Selected Details for E-mail</title>

// To pop-up the outlook & send the mail

<script type = "text/javascript" src = "script/mail.js"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnSendEmail').click(function (event) {
        var email = 'sendermail@email.com';
        var subject = 'sender Subject';
        var emailBody = 'body'; 

//here in EmailBody I want to print the data collected from the page

        window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
      });
    });
  </script>
</head>



<body bgcolor = #B0D1F3>
<br /><br/>
User <b><?php echo $uname;?></b>  has requested to refresh  <b><?php echo $_POST["name"]; ?></b> with  <?php 
if(!empty($_POST["list"])) {
$snapname = $_POST['list'];
echo "snapname :<b> ".$list." </b><br/>";
}
else {
echo "<b>Please Select the list items.</b>";
}
?><br/>

With following Commands:
<?php
if(isset($_POST['submit'])){
if(!empty($_POST['instance'])) {
$checked_count = count($_POST['instance']); // Counting number of checked checkboxes.
echo "(You have selected following) <b>".$checked_count."</b> option(s): <br/>"; // Loop to store and display values of individual checked checkbox.
foreach($_POST['instance'] as $selected) {
echo "<p><b>".$selected ."</b></p>" ; 
}
}
else{
echo "<b>Please Select Atleast One Option.</b>";
}
}
?>

 <div>
    <INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"> 
    <button class="btnSendEmail">Send Email</button><br /><br /> 

// on click of Send Email button, it gives me the outlook and body should contain the data on that page which is processed from prvious page

 </div>
</body>
</html>

Recommended Answers

All 2 Replies

I guess you could Jquery width AJAX to collect details of your form data.
I couldn't understand your question well;

You could do something like:

$(document).ready(function(){
 $("#submit").click(function(){
 var submit = $(this).val();
  $.post('page_name.php',{submit:submit},function(data({
  $("#submit_span").html(data);
  });
 });
})

You need to create a span page to display the data

Are you sending the user to another URL or the same page? If not, you need to add the Javascript in your button "onclick" event and add Ajax part of Javascript. If you want to use the current script (which seems to show that you want to send data to the same page), you must add "form" tag and set the target action to the same page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.