php enquiry popup

Need technical advice on coding your web pages? Covers HTML, JavaScript, CSS, and some server side technologies. Also the issue of some webpages not displayed well.

Moderator: Don_HH2K

php enquiry popup

Postby justdan » Tue 25 Apr, 2006 5:21 am

Hey all,

i need help with carrying hidden data from a page to a popup. Bascially i have a page with an item on it. This item has an item code, i want to put in an enquiry button on the page. so that when a customer clicks on it a pop up opens. The pop up will have a small enqury form on it with all the usually fields on. The problem i have is that i want the pop up to open with the item code already in a item code field. This will save the customer having to look wat the product number is of the product that they want an equiry about is.

Still with me....

Anyway. i figured i'd use a small form like the following:

Code: Select all
<form method='post' target="_blank" action"submit">
<input type='hidden' name=Itemcode value='001'>
<input name="submit" type=submit class="style11" value='Equiry' />
</form>


But i don't want the target to be _blank i want to run some jsript off the button!...... is this possible? e.g. action='javascript:namehere()'

So can anyone help me

1)open a popup off a form button
2) carry the item code from the main page to a field on the popup

Thanks in advance

justdan

msn = static711@hotmail.com
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2
Last edited by justdan on Tue 25 Apr, 2006 5:33 am, edited 1 time in total.
justdan
junior member
junior member
 
Posts: 7
Joined: Thu 23 Mar, 2006 11:24 am

Re: php enquiry popup

Postby akbash » Thu 27 Apr, 2006 11:01 am

But i don't want the target to be _blank i want to run some jsript off the button!...... is this possible? e.g. action='javascript:namehere()'
You can attach a submit handler to the form or to the submit button:
Code: Select all
<script>
function doStuff() {
  // this function will be called when the user clicks Submit
}
</script>
<form onsubmit="doStuff()">
  <input type="submit">
</form>

i want the pop up to open with the item code already in a item code field.
The most straightforward way is to take the field value from the form data submitted from the original page. A form like
Code: Select all
<form action="processForm.html">
  <input type="hidden" name="itemcode" value="001">
  <input type="submit">
</form>
will load a URL like "processForm.html?itemcode=001" when submitted. processForm.html like this
Code: Select all
<html><head>
<script>
function processParameters() {
  var fieldPos = document.location.href.indexOf("?")
  // was the page was loaded with arguments encoded in the URL?
  if (fieldPos >= 0) {
    // isolate the arguments
    var parameters = document.location.href.substr(fieldPos+1)
    var valuePos = parameters.indexOf("=")

    // process a single argument of the form "id=value"
    document.getElementById(parameters.substr(0,valuePos)).value =
      unescape(parameters.substr(valuePos+1))
  }
}
</script>
</head><body onload="processParameters()">
<form>
  item code <input type="text" id="itemcode">
</form>
</body></html>
would pre-load that value into its own form.
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20060305 Firefox/1.5
akbash
silver member
silver member
 
Posts: 364
Joined: Mon 09 Feb, 2004 9:13 pm

Postby justdan » Thu 04 May, 2006 4:13 am

thanks for the reply, in the end i just added a enquiry form button on each product page. I just added a hidden input to the enuiry button, which was the item code i wanted to be carried across. Like below;

Code: Select all
<form action="EnquiryForm.php" target="_blank" method="post">
    <input type='hidden' name=Itemcode value='itemcodehere'>
    <input type="submit" class="style11" value="Enquiry">
</form>   


Then when EnquiryForm.php was opened i used a onLoad function to resize the window to a popup like size. Somthing like;

Code: Select all
<body onload="window.resizeTo(350,580);">


And then to place the hidden item code into the EnquryForm i just used php to move the hidden input field where i wanted it. With somthing along the lines of;

Code: Select all
<?php
  foreach($_POST as $key=>$value){
    if ($key!="submit"){
      $value=htmlentities(stripslashes(strip_tags($value)));
      echo "\t<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
    }
  }
?>


so now when a customer sends an enquiry about a product, who ever's reading the enquiry will know wat product the customer is equiring about.
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.3) Gecko/20060426 Firefox/1.5.0.3
Last edited by justdan on Thu 04 May, 2006 4:18 am, edited 2 times in total.
justdan
junior member
junior member
 
Posts: 7
Joined: Thu 23 Mar, 2006 11:24 am


Return to Web Design and Page Coding

Who is online

Registered users: Google [Bot], Yahoo [Bot]