I have a PHP form with a html section at the bottom. There are 14 input text fields on the form and I want the form to send of the email as it should do and also take the name field, pass it to the following web page and display it in a <div> tag.

I think the relevant code looks like this

PHP section

$FName = 'Sub Contractor';
$FWebsiteAfter = 'http://www.website.com/inductionCardSub.html';
$FieldName[0] = 'Your Name';
$Hida2 = trim($_POST['hida2']);

HTML section

<form method="post" action="" enctype="multipart/form-data">
<input type="text" name="FieldData0" value="<? echo $FieldData[0] ?>" maxlength="100" size="30"  /><? echo ' ' . $mmsg[1];
?>
<input type="text" name="hida2" value="" maxlength="100" size="3" style="display : none" />
<input type="submit" class="btn" value="SUBMIT" name="Submit"  />
</form>

Can I capture the input from FieldData0 and send it to the next webpage by Javascript or as a cookie? Or to have then confirm their name in a second form and automatically capture it before the submit button.

I have no script on the following page yet.

Thanks

Recommended Answers

All 22 Replies

Hi,

Javascript itself cannot obtain those value from the user input, and moving it to the next page, unless you prefer saving those data using cookie session. But why do you need JavaScript for this job? Knowing that PHP alone can handle all sorts of data you need from the user w/o using javascript cookie session...

Hi,

I don't have very much PHP experience and a little Javascript learnt about 6 years ago. I was hoping that I could have done it easy with Javascript. I will buy a PHP book today and see if I can work it out from that.


The people who wrote he form don't reply to my requests

Hi Mel64,

Do you still need a working example of this in Javascript?

Yes please, That would be great.

Regards

Would this work on the next page

<div>
   <?php
       print ("$FieldData0" );
  ?>
</div>

Yes that would work, but if want to capture the exact user inputted entry, then you could try something like:

<?php echo $_POST['FieldData0']; ?>

No it didn't work. I just have a blank area on the following page.

Hi Mel,
Here's a simple demo:

<form id="testform" action="nextpage.php" method="post">
<div>Test Field: <input type="text" id="FieldData0" name="FieldData0" value="" size="30" /> <input type="submit" value="submit" />
</div>
</form>

on the nextpage.php the code would look something like:

<html>
<head>
<body>
<h1><?php 
$testfield = $_POST['FieldData0'];
   if ( isset( $testfield )) { 
   echo $tesfield;
   } 
else { echo "Failed to capture entries"; } ?></h1>
</body>
</html>

Thanks, that has worked a treat.

Much appreciated.

You are welcome...

Again thank you for you help but I didn't realise that when I put the action"" into the form tag, the name field works but the form no longer sent the email and you don't have to fill in the required fields to submit the form. As soon as I take out the action the name doesn't work and the form does.

Any quick thoughts?

Hi,

I am sorry, but i wont be able to provide you with the exact examples' that involves PHP. This type of data handling, will require some PHP form mailer, which i cannot run here. So i would suggest, that you should try the PHP section, regarding this issue. Im sure those guys from there would be happy to provide you with the exact information that you need on resolving this matter.

But if you still need something with javascript, don't hesitate to post back on us...

-essential

Thank you. for you help. Is there any javascript that will take the value to the next page?

Thanks

Yes, and that would be the used of cookie session / or a new popup window. Just let me know, If you need some sample code.

Yes I would. the target page will be the mainFrame of a frameset so a popup is out. I was thinking about cookies.

Thanks

Mistake in line 7.

Should read '$testfield' not '$tesfield'

Thanks, I picked that on up and it worked well.

The offending code is the form action on the first page.

how much data are you trying to pas to the folowing page?
-cause if it's only a Name and/or Surname, you won't be needing 'php', 'cookies' or similar ...

its only the full name of the user captured in one field. The form as a whole, 14 questions is to be sent to email. The code from the php sample previous listed works well but having a the following page address causes the php form to fail.

OK leave everything else as is and since you know some javascripting, than
I suggest you use the browser address-bar for data persistence!
:)

get the "full name" variable and append it to the location string of the following page using "?" mark i front.

than from the following page you will be able to extract the data passed to url after the ? mark, with ease.

Hi guys,

Why it never came up to my idea. TroyIII this saves me alot of work. The only problem that we have here, is that we wont be able to preserve those data for farther use. Anyways here's some lite demo.

We'll start on the first page and here's the to it:
startpage

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css_level21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>http://www.daniweb.com :: DHTML  JavaScript / AJAX</title>
<style type="text/css">
/* <![CDATA[ */
td:first-child {
  letter-spacing : 3px; }
td, th { 
   font : bold normal normal 80%/1.5 Verdana, Arial, sans-serif;
   color : #778899;
   letter-spacing : 3px;
   border : 1px solid #ccc;
   padding : .500em 1em .500em 1em; }
table {
   border-top : 1px solid #ccc;
   border-collapse : collapse; }

/* ]]> */
</style>
<script type="text/javascript">
// <![CDATA[

var validate = ( function( form ) {
var form = form || 0;
   if ( form ) {
      var check = /^[a-zA-Z0-9]+$/;
      var user = [form.uname.value, form.pword.value];
      for ( x = 0; x < user.length; x++ ) {  
         if ( !check.test( user[ x ] )) {
            alert( user[ x ] + " : is not a valid entry" )
            return false;
         } else {
            form.action += "#" + user[ x ];
         }
      }
   } 
} );

// ]]>
</script>
</head>
<body>
<div id="main">
<form id="testform" action="nextpage.html" method="post" onsubmit="return validate( this );">
<table border="0" id="table" frame="void" rules="none" width="100%" summary="JavaScript :: live demo" cellspacing="4" cellpadding="4">
<tr>
<th><label for="uname">username :</label></th>
<td><input type="text" id="uname" name="uname" size="30" value="" /></td>
</tr>
<tr>
<th><label for="pword">password :</label></th>
<td><input type="password" id="pword" name="pword" size="30" value="123456" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="submit" /></td></tr>
</table>
</form>
</div>
</body>
</html>

we're almost done, and
here's the code for the nextpage.

nextpage.html

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css_level21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>http://www.daniweb.com :: DHTML  JavaScript / AJAX</title>
<style type="text/css">
/* <![CDATA[ */

td, th { 
   background-color : #f0f0f0; 
   font : bold normal normal 80%/1.5 Verdana, Arial, sans-serif;
   color : #405060;
   letter-spacing : 3px;
   border : 1px solid #ccc;
   padding : .500em 1em .500em 1em; }
table {
   border : 1px solid #405060;
   border-collapse : collapse; }

/* ]]> */
</style>
<script type="text/javascript">
// <![CDATA[
onload = ( function() {
var userData = location.hash.split( "#" );

   alert( "Welcome " + userData[ 1 ] );
var form = testform;
var user = [ form.uname, form.pword ];
   for ( x = 0; user.length; x++ ) {
      user[ x ].value = userData[ (( x ) + 1 ) ];

   }
} );


// ]]>
</script>
</head>
<body>
<div id="main">
<form id="testform" action="nextpage.html" method="post" onsubmit="return false;">
<table border="0" id="table" frame="void" rules="none" width="100%" summary="JavaScript :: live demo" cellspacing="4" cellpadding="4">
<tr>
<th><label for="uname">username :</label></th>
<td><input type="text" id="uname" name="uname" size="30" value="" /></td>
</tr>
<tr>
<th><label for="pword">password :</label></th>
<td><input type="text" id="pword" name="pword" size="30" value="" /></td>
</tr>

</table>
</form>
</div>
</body>
</html>

-essential

Thanks for the help. I will ad another page and post it from there using the test from an earlier reply.

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.