Jump to content

If submit is clicked, open a new window


fri3ndly

Recommended Posts

Hello :-)

 

I have a form which I need to do two things when submitted, but at the moment I can only make it do one  ???

 

When submit is clicked I need 'step2' to load (which it does), but I also need a new browser window top open with a certain domain (depending on what item was selected according to php variable).

 

Basically a pop up

 

Any ideas? Is this out of PHP's hands?

Link to comment
Share on other sites

Thanks for the comments guys

 

Basically, yes it is to an external domain.

 

The user will select from a load of different companies, and when they hit submit the next part of the form will load on the current page and a new window will also be opened to take them to the website

Link to comment
Share on other sites

<script type="text/javascript">

function popup()

{

testwindow= window.open ("pagetogoto.html", "mywindow",

    "location=1,status=1,scrollbars=1,width=100,height=100");

}

</script>

<button onclick="javascript: poponload()">

<h1>JavaScript</h1>

 

 

Link to comment
Share on other sites

Thanks gameyin

 

But what that does is indeed open a new window, but I cannot also instruct the new part of php code as the page does not refresh.

 

My second idea is this though...

 

Can I have two submit buttons, one of which is disabled until the first is pressed. Once it is pressed, the next button becomes available.

 

I have seen this done before?

 

Thanks

Link to comment
Share on other sites

You could have....

<form method="post" action="ldfjasldfj.php">

<input type="submit" value="Submit1">

<input type="submit" value="Submit2" onclick="<? if(isset($_POST['Submit1']) { LET THIS GO THROUGH; } else { DONT LET THIS GO THROUGH; } ?>

</form>

 

I won't write the entire script out for you but there's a start.

Link to comment
Share on other sites

this is a simple one that will open a new window with the domain selected and also submit the form to wherever you want.

<script type="text/javascript" >
function winOpen(){
var domain = form1.sitename.value
  site="http://www."+domain
  window.open(site);
}
</script>
<?php
if(isset($_POST['submit'])){
print_r($_POST);
} else {
?>
<form name=form1 action="" method=post />
<select name=sitename>
<option value="theelders.net">The Elders</option>
<option value="phpfreaks.com">PHP Freaks</option>
</select>
<input type=submit name=submit value=Submit onClick="return winOpen();"/>
</form>
<?php
}
?>

 

Ray

Link to comment
Share on other sites

Thanks for all the responses. I have tried them all and having no luck! I think its because the php script will need to rerun but nothing is making it.

 

I think it would be best if I paste up my code for you to see, that might explain my aim a little better....

 

		<div id="step1">
		<h2>Find Discounts For...</h2>
		<p>Please the store you wish to find discounts for from the list below.</p>
		<form method="post" action="<?php echo '?page=step2'; ?>">
		  <label>
		  <select name="select">
		    <option value="-" selected="selected">-</option>
		    <option value="dixons">Dixons</option>
		    <option value="hmv">HMV</option>
		    <option value="thomson">Thomson Holidays</option>
	      </select>
		  </label>
		 <label>
              <input type="submit" name="submit" value="Find Discount Codes" />
              </label>

		</form>
	</div>
	<?php
	$select = $_POST['select'];

	 if ($page == 'step2' && $select != '-'){ ?>
  <div id="step2">
		<h2>Visit Retailer...</h2>
	  <p>Click the link below to visit the store and activate discounts. Once you have clicked the link, it will open in a new window and the discount codes will be displayed below. </p>

	<form method="post" action="" target="_blank">
	<input type="submit" value="Submit1" onclick="http://www.dixons.com/ (IN A NEW WINDOW)">
	<input type="submit" value="Submit2" disabled="disabled" (UNLESS Submit1 HAS BEEN CLICKED. IF IT HAS 'step3' WILL BE DISPLAYED) />
	</form>

    </div>
	<?php } ?>
	<?php if ($page == 'step3'){ ?>
	<div id="step3">
		<h2>View Codes...</h2>

Link to comment
Share on other sites

Do you need to pass parameters to the discount page?.

If you don't my code will submit the dropdown to your page to parse and also open a window to the page they selected.

 

<script type="text/javascript" >
function winOpen(){
var domain = form1.select.value
  site="http://www."+domain+".com"
  window.open(site);
}
</script>
<div id="step1">
		<h2>Find Discounts For...</h2>
		<p>Please the store you wish to find discounts for from the list below.</p>
		<form name=form1 method="post" action="<?php echo '?page=step2'; ?>">
		  <label>
		  <select name="select">
		    <option value="-" selected="selected">-</option>
		    <option value="dixons">Dixons</option>
		    <option value="hmv">HMV</option>
		    <option value="thomson">Thomson Holidays</option>
	      </select>
		  </label>
		 <label>
              <input type="submit" name="submit" value="Find Discount Codes" onClick="return winOpen();"/>
              </label>

		</form>
	</div>
	<?php
	$select = $_POST['select'];
    $page = $_GET['page'];

	 if ($page == 'step2' && $select != '-'){ ?>
  <div id="step2">
		<h2>Visit Retailer...</h2>
	  <p>Click the link below to visit the store and activate discounts. Once you have clicked the link, it will open in a new window and the discount codes will be displayed below. </p>

	<form method="post" action="" target="_blank">
	<input type="submit" value="Submit1" onclick="http://www.dixons.com/ (IN A NEW WINDOW)">
	<input type="submit" value="Submit2" disabled="disabled" (UNLESS Submit1 HAS BEEN CLICKED. IF IT HAS 'step3' WILL BE DISPLAYED) />
	</form>

    </div>
	<?php } ?>
	<?php if ($page == 'step3'){ ?>
	<div id="step3">
		<h2>View Codes...</h2>
      <?php
      }
      ?>

 

Once they select the retailer they want, then just run your code in step 2.

 

Ray

 

 

Link to comment
Share on other sites

All it needs to have is a certain url before the page something like this (which is the same for all of them)

 

 

http://www.affiliateplace.com/?sdfdf=4353453&p=http://www.dixons.com/

http://www.affiliateplace.com/?sdfdf=4353453&p=http://www.hmv.com/

http://www.affiliateplace.com/?sdfdf=4353453&p=http://www.thomson.com/

 

The dropdowns will all be looked up from a database and so will the url value.

 

Will that script work then?  ;D

Link to comment
Share on other sites

Yes if you populate the value of the dropdown with the exact page you want to go to, All you would need to do is change the javascript to this

 

<script type="text/javascript" >
function winOpen(){
var domain = form1.select.value
  window.open(domain);
}
</script>

 

Ray

Link to comment
Share on other sites

Im really lost, Do  I still need to use the 3 submit buttons on the page?

 

I have uploaded the php and css file (http://www.gigasize.com/get.php?d=9w0yrc51pkb) for you as I can tell you know what your talking about. If you get a minute please can you take a look.

 

Also, can php be used inside javascript to GET the new domain from the string?

Link to comment
Share on other sites

If you would like to talk to me better I am on AIM screen name craygo69.

 

And to answer your question, yes you can use php inside of javascript.

 

You are using a database to store information??

 

Ray

Link to comment
Share on other sites

Sorry I dont have AIM at work, have msn.

 

Yes I will be using a database which will consist of

 

- shop name

- discount code

- discount code expiry

- url to direct to

 

So the drop down will be populated with all available shops, and the link will be passed to the query string on the page refresh to which the page will know what url to load for the popup.... or something :D

 

Link to comment
Share on other sites

Would be something like this:

 

-- phpMyAdmin SQL Dump
-- version 2.10.1
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Apr 09, 2008 at 04:18 PM
-- Server version: 5.0.45
-- PHP Version: 5.2.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

-- 
-- Database: `ilovediscounts`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `discounts`
-- 

CREATE TABLE `discounts` (
  `id` int(5) NOT NULL auto_increment,
  `company` varchar(50) NOT NULL,
  `description` text NOT NULL,
  `code` varchar(50) NOT NULL,
  `expiry` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

-- 
-- Dumping data for table `discounts`
-- 

INSERT INTO `discounts` (`id`, `company`, `description`, `code`, `expiry`) VALUES 
(1, 'Dixons', '10% off everything', '7tHYEEn77', '2008-04-25'),
(2, 'HMV', 'Free postage', '9yuemKBN', '2010-04-15');

-- --------------------------------------------------------

-- 
-- Table structure for table `login`
-- 

CREATE TABLE `login` (
  `id` int(2) NOT NULL,
  `username` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  `fullname` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- 
-- Dumping data for table `login`
-- 

Link to comment
Share on other sites

OK I added a couple fields to your table, hope you don't mind.

 

table:

-- Table structure for table `discounts`
-- 

CREATE TABLE `discounts` (
  `id` int(5) NOT NULL auto_increment,
  `company` varchar(50) NOT NULL,
  `url` varchar(100) NOT NULL,
  `description` text NOT NULL,
  `code` varchar(50) NOT NULL,
  `items` varchar(50) NOT NULL default 'ANY',
  `expiry` date NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

-- 
-- Dumping data for table `discounts`
-- 

INSERT INTO `discounts` VALUES (1, 'Dixons', 'http://www.awin1.com/awclick.php?awinmid=550&awinaffid=78426&p=http://www.dixons.com', '10% off everything', '7tHYEEn77', 'ANY', '2008-04-25');
INSERT INTO `discounts` VALUES (2, 'HMV', 'http://www.awin1.com/awclick.php?awinmid=550&awinaffid=78426&p=http://www.hmv.com', 'Free postage', '9yuemKBN', 'ANY', '2010-04-15');
INSERT INTO `discounts` VALUES (3, 'Dixons', 'http://www.awin1.com/awclick.php?awinmid=550&awinaffid=78426&p=http://www.dixons.com', '', '155d454e', 'ANY', '2008-12-25');

 

And here is the code for the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>I Love Discounts</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" >
function winOpen(){
var domain = document.getElementById('domain');
  site=domain.value;
  window.open(site);
}
</script>
</head>
<body>
<div id="wrapper">
<?php
// Make database connection here


if(!isset($_POST['submit'])){
?>
	<div id="header">
		<div id="logo">
			<h1>Discounts Codes | Discount Vouchers | Discount Coupons</h1>
			<img src="images/logo.jpg" width="200" height="37" alt="I Love Discounts" />
	 	 </div>
	</div>
	<div id="step1">
		<h2>Find Discounts For...</h2>
		<p>Please the store you wish to find discounts for from the list below.</p>
		<form name="form1" method="post" action="" />
		  <label>
		  <select name="select" id="domain" />
        <option value="-" selected="selected">Please Select One</option>
        <?php
        $sql = "SELECT DISTINCT `company`, `url` FROM `discounts` WHERE `expiry` >= NOW()";
        $res = mysql_query($sql) or die(mysql_error());
        while($r = mysql_fetch_assoc($res)){
          echo "<option value=\"".$r['url']."\">{$r['company']}</option>\n";
        }
        ?>
	      </select>
		  </label>
		<label>
              <input type="submit" name="submit" value="Find Discount Codes" onClick="return winOpen();"/>
              </label>

		</form>
	</div>
<?php
} else {
$url = $_POST['select'];
    ?>
	<div id="step3">
		<h2>View Codes...</h2>
		<p>View the current discount codes for your chosen retailer below.<br />
		Copy and Paste the discount code of your choice into the website that has opened at checkout stage.</p>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td>CODE</td>
                <td>DISCOUNT</td>
                <td>ITEM (IF SPECIFIC) </td>
                <td>Expires</td>
              </tr>
                <?php
                $sql = "SELECT * FROM `discounts` WHERE `url` = '$url'";
                $res = mysql_query($sql) or die(mysql_error());
                while($r = mysql_fetch_assoc($res)){
                echo "<tr>
                        <td>{$r['code']}</td>
                        <td>{$r['description']}</td>
                        <td>{$r['items']}</td>
                        <td>{$r['expiry']}</td>
                      </tr>\n";
                }
                ?>
            </table>
		</div>
	<div id="footer">
	© 2008 - 'I Love Discounts' is a trading name of Friendly Websites LTD
	</div>
  <?php
  }
  ?>
</div>
</body>
</html>

 

Hopefully it's what you want :)

 

Ray

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.