Forum Moderators: coopster

Message Too Old, No Replies

How to populate URLs with affiliate id on form submit?

         

1shotoffers

2:46 pm on Apr 18, 2010 (gmt 0)

10+ Year Member



Hello all,

I am trying to figure out a way to add a form to a page from which a user would input their affiliate id number or name and upon submit, it would populate all instances of the base URL on the page

so, where base URL is [thesite.com...] upon their entering the info and clicking submit, it would be changed to:

[thesite.com...]

Can someone help?

mack

2:50 pm on Apr 18, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



The easiest way to achieve this would be to have the form field and a submit button, then point the form to the same page. When the page reloads extract the post data that will then contain the user supplied data.

Mack.

Readie

3:02 pm on Apr 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do it:

$loc = '/?e=' . $_POST['affiliate'];
header("Location: $loc");

However, to reduce hits on the server, it may be best to do this as well (keep the PHP for when people disable JS):

<form onsubmit="return affi(this)" action="/processing.php" method="post">
<input type="text" name="affiliate" id="affiliate" />
<input type="submit" />
</form>
[code][/code]<script type="text/javascript">
var afi = document.getElementById('affiliate').value;
function affi(form) {
if(afi != "") {
window.location.href = "/?e=" + afi;
} else {
alert("Please enter an affiliate ID.");
}
return false;
}
</script>

Will also get a smoother experience for the users with the JS - they'll only have one page load and not two.

1shotoffers

3:19 pm on Apr 18, 2010 (gmt 0)

10+ Year Member



First, thanks so much for this help!

Ok...I so I think I get it....(I'm a total nubie...)

So I would create "processing.php" which would include
$loc = '/?=' . $_POST['affiliate'];
header("Location: $loc");


The javascript form verify I get.....

But in the HTML on the page, how do I call the submitted info into the base URL?

would it be like
 http://www.thesite.com/?e=<?php echo $affiliate ?>


Thanks

1shotoffers

3:32 pm on Apr 18, 2010 (gmt 0)

10+ Year Member



I figured it out and it's working so THANKS AGAIN!