Jump to content

Collecting hidden form data from within page

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Collecting hidden form data from within page Rate Topic: -----

#1 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 15 October 2006 - 09:35 AM

How would I go about collecting a form value from somewhere which is not located in the form?

For example :

-- Here is my Product Name . (This is contained at top of the web page, not within a form.)

<form>
<input type="hidden" name="product_name" value="product_name_here"/> 
</form>


How would I get the Product name from the top of the webpage to display in the value="product_name_here"?
0

#2 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 15 October 2006 - 11:15 AM

i think i know what u mean...

i think....lol

if its what im thinking your building some form of online store..maybe? anyway this solution is a universal concept...

say u have a category page. on there, link to your products with a querysting...

<a href="products.php?item_code=1">Buy this hat</a>


On products.php, you will want the following php...

<?
if ($_GET['item_code']) 
{
	 echo "<input type='hidden' name='product_name' value='".$_GET['item_code']."'/>";
}
else
{
	 // Do somthing to tell the user to select a product....
}
?>

am i on the right lines?

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#3 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 15 October 2006 - 11:43 AM

You well may be the on the right lines, but I'm not sure if I am now! :lol: Thanks, good answer though.

What it's for is a page where a user submits a review of a resturant. The html page they are seeing is of a particular resturant (www.reviewsite.com/resturant1.html).

On that html page is a form which a user can fill out to review the resturant. Rather than getting them to fill out the name of the resturant they are already viewing, I would rather it be so that the name of the resturant is hidden within the form when it is sent to me. I have been previously just having the value as hidden. However, I'm now wanting to use a template within Dreamweaver for the form, so if I want a to make a change I don't have to manually apply it to each individual html page.

The problem is, the template function does not allow editable regions within form tags, so the whole process becomes pointless. What I'm trying to do is when I create a new review html page from a template, all I need do is fill in the hidden value in the form with the name of the resturant, the rest of the form remains true to the template. This hidden value then gets picked up and emailed to me from the PHP process.

Maybe I am going about this the wrong way? Maybe templates/editable regions are a bad idea? If I could get this to work how I want it I would be very pleased.
0

#4 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 15 October 2006 - 12:21 PM

View Postwgardner, on Oct 15 2006, 05:43 PM, said:

Maybe I am going about this the wrong way? Maybe templates/editable regions are a bad idea? If I could get this to work how I want it I would be very pleased.

id say so...you really want to look at using a dynamic page...better for so many reasons...

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#5 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 15 October 2006 - 12:33 PM

View Postbenbramz, on Oct 15 2006, 06:21 PM, said:

id say so...you really want to look at using a dynamic page...better for so many reasons...


Right, I better get on it then. Thanks for your help :blush:
0

#6 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 15 October 2006 - 01:19 PM

There's a little javascript you could use to grab the name from the page and put it in your form.

You'd want the name of the place to be inside something like a DIV tag, then in JS use

document.GetElementByID("hiddenfieldname").value = document.GetElementByID("divid").innerHTML


You could fire that line on the form submit or page load. Or of course you could use PHP as already mentioned.

If you need more info on how to use this code let me know.
0

#7 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 15 October 2006 - 03:10 PM

View PostCatalyst, on Oct 15 2006, 07:19 PM, said:

If you need more info on how to use this code let me know.


PM'ed :arrow:
0

#8 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 15 October 2006 - 05:38 PM

OK, so the easiest would be to just stick this in the form tag like:

<form onsubmit="document.GetElementByID('hiddenfieldname').value = document.GetElementByID('divid').innerHTML">

0

#9 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 16 October 2006 - 03:10 AM

View PostCatalyst, on Oct 15 2006, 11:38 PM, said:

OK, so the easiest would be to just stick this in the form tag like:

<form onsubmit="document.GetElementByID('hiddenfieldname').value = document.GetElementByID('divid').innerHTML">

nice method! not too hot with javascript.. :glare:

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#10 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 16 October 2006 - 04:01 AM

View Postbenbramz, on Oct 16 2006, 09:10 AM, said:

nice method! not too hot with javascript.. :glare:


Yes, excellent! Thanks, I'll give this a go when I get back later. ^_^
0

#11 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 16 October 2006 - 09:55 AM

I may be heading in the wrong direction completly, but I can't get the PHP script to 'gather and post' the data that should be aquired from the javascript.

Also, I'm not entirely sure of what should be in 'hiddenfieldname' - is this just an ID for the data or should it refer to a different hidden field within the form?

Below is my code for both HTML form and PHP mailer script.

HTML :
<form action="../php/newreview_form.php" method="post" name="submit_review" class="review_form">
<form onsubmit="document.GetElementByID('hiddenfieldname').value = document.GetElementByID('resturant_name').innerHTML">
<input name="Submit" type="submit" value="Submit" />
</form>

<div id="resturant_name">Curry house 1</div>


PHP :
<?php

// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$res_name = addslashes($_POST['resturant_name']);

//Sending Email to form owner
$pfw_header = "From: $name\n"
  . "Reply-To: $name\n";
$pfw_subject = "New curry test";
$pfw_email_to = "*MYEMAILHERE*";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "res_name: $resturant_name\n"
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header );

header("Location: Untitled-10.html");

?>



When you got a chance, I'd be so thankful for some guidence.

I also tried it like this : (thinking that the javascript line may need a name tag to enable the PHP script to pick up the data. As you can guess, this didn't work.
HTML:

<form action="../php/newreview_form.php" method="post" name="submit_review" class="review_form">
<form name="resturant_name" onsubmit="document.GetElementByID('resturant_title').value = document.GetElementByID('resturant_name').innerHTML"/> 
<input name="Submit" type="submit" value="Submit" />
</form>

<div id="resturant_name">Curry house 1</div>

0

#12 User is offline   Ben Abrams 

  • The buddy system:never fails
  • Group: Administrators
  • Posts: 1,850
  • Joined: 04-April 06
  • Gender:Male

Posted 16 October 2006 - 10:53 AM

View Postwgardner, on Oct 16 2006, 03:55 PM, said:

Also, I'm not entirely sure of what should be in 'hiddenfieldname' - is this just an ID for the data or should it refer to a different hidden field within the form?

hiddenfieldname should be your hidden field name...like hidden1 or moomoothesheep:

you define it...

View PostSirkent, on 21 September 2007 - 04:26 AM, said:

<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
0

#13 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 16 October 2006 - 11:02 AM

View Postbenbramz, on Oct 16 2006, 04:53 PM, said:

hiddenfieldname should be your hidden field name...like hidden1 or moomoothesheep:

you define it...


Would this be the field name that the PHP refers to?
0

#14 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 16 October 2006 - 02:01 PM

You don't want 2 FORM tags, just combine everything together into one tag.
0

#15 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 17 October 2006 - 10:26 AM

View PostCatalyst, on Oct 16 2006, 08:01 PM, said:

You don't want 2 FORM tags, just combine everything together into one tag.


Ah thanks Catalyst, that solves it. I was making a school boy error and everything is dandy now.

You have some skills I must say. Thanks for your time.

(Looks like I forgot to use the answerable topic element here, so feel free to lock this thread if necessary etc)

This post has been edited by wgardner: 17 October 2006 - 10:26 AM

0

#16 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 17 October 2006 - 10:39 AM

Yes, the force is strong with Catalyst.
0

#17 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 17 October 2006 - 11:15 AM

I made the topic answerable, use it as you normally would!!
0

#18 User is offline   william 

  • SEO Specialist
  • Group: Members
  • Posts: 233
  • Joined: 13-October 06
  • Gender:Male
  • Location:Gloucestershire, UK
  • Interests:SEO, Web Design, PHP Development, Wordpress, Fireworks, Photoshop, EpiServer

Posted 17 October 2006 - 12:29 PM

This is a great method for gathering data from outside a form, from elsewhere on the webpage.
0

#19 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 17 October 2006 - 04:44 PM

Yeah, I usually use it in the opposite way. To put HTML on the page based on what's in a form field for example, very hand for giving validation messages, etc.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users