Here's the problem:
We have a website where users can request a quote for a wedding ring. There are 12 rings per collection. There are 16 collections. Each collection has its own page.
Sample page: http://ringsunique.com/unique-wedding-rings/damascus/
We want the customer to request a quote for one of the rings on the page. An example of a link to get a quote is: <a href="http://ringsunique.com/openquote/?ring=damascus1" class="jcode_inner_link">Get your quote on Damascus 1</a>
That generates this page: http://ringsunique.com/openquote/?ring=damascus1
Once you submit a request, you go here: http://ringsunique.com/openquote/?word=thanks
I am trying to give the user on this last page (word=thanks) the chance to link back to the original collection page. (In this case, the Damascus collection.)
I am including the code for the openquote and word=thanks pages at the very bottom.
I hired someone to code this. I'm sort of a PHP hack and have tried to get this to do what I want, but have failed miserably.
This is the code I came up with:
<?php
$url = ($_SERVER['HTTP_REFERER']);
// remove final "/"
$url = rtrim($url, '/');
// remove everything before the "/" before collection name
$shorty = str_replace('/', '^', $url);
$shorty = preg_replace('/^.*^\s*/', '', $shorty);
$shorty = trim(substr($shorty, strrpos($shorty, '^') + 1));
// echo url to screen
echo '<a href="'.$url.'">Return to '.ucfirst($shorty).' Collection</a>';
?>
Actually, this code works if I want to write to the screen from the openquote page. It links to the Damascus Collection. But when I put my code in the section that writes the word-thanks page, then it writes the url of the openquote page not the Damascus page.
I've spent hours trying to figure this out. Thank you for any help you can lend!
<?php
/*Template Name: OpenQuote*/
?>
<?php get_header(); ?>
<?php $top_links_options= get_option('top_links_options'); ?>
<?php $side_links_options= get_option('side_links_options'); ?>
<body style="background: url(<?php bloginfo('template_directory');?>/images/aboutus/main_bg.jpg) repeat-x scroll 0px 0px rgb(131, 127, 115);">
<div class="arch_main">
<script language="javascript" type="text/javascript">
function checkForm() {
if(document.getElementById('ring_size').value=="")
{
alert('Please enter Ring Size');
document.getElementById('ring_size').focus();
return false;
}
if(document.getElementById('yourname').value=="")
{
alert('Please enter Your Name');
document.getElementById('yourname').focus();
return false;
}
if(document.getElementById('address').value=="")
{
alert('Please enter Mailing Address');
document.getElementById('address').focus();
return false;
}
if(document.getElementById('city').value=="")
{
alert('Please enter City');
document.getElementById('city').focus();
return false;
}
if(document.getElementById('state').value=="")
{
alert('Please enter State');
document.getElementById('state').focus();
return false;
}
if(document.getElementById('zip').value=="")
{
alert('Please enter Zip Code');
document.getElementById('zip').focus();
return false;
}
if(document.getElementById('email').value=="")
{
alert('Please enter Your E-mail address');
document.getElementById('email').focus();
return false;
}
if(document.getElementById('email').value != document.getElementById('confirmemail').value )
{
alert('E-mail address does not match with Confirm E-mail address');
document.getElementById('confirmemail').focus();
return false;
}
return true;
}
</script>
<?php
if(isset($_POST['sendemail'])){
//$recipient='rings@ringsunique.com';
$name = $_POST['yourname'];
$email= $_POST['email'];
$subject= 'Rings Unique Quote Response';
$ringname=$_POST['ring_name'];
$ringsize=$_POST['ring_size'];
$mailing_add=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$phone=$_POST['phone'];
$comment=$_POST['comments'];
$body="Ring Name:".$ringname."\nRing Size:".$ringsize."\nMailing Address:".$mailing_add."\nCity:".$city."\nState:".$state."\nZip Code:".$zip."\nPhone:".$phone."\nMessage:".$comment;
// E-mail to Admin
mail('rings@ringsunique.com',$subject,$body,"From: $name<$email>");
//@wp_mail($recipient, 'fdsfsf', 'fdfsfsf');
}
?>
<!-- TEXT -->
<div id="main-text">
<?php if($_REQUEST['word']=='thanks'){?>
<h1>We Will Contact You Within One Business Day</h1>
Thank you for requesting a quote from Rings Unique. We will view your request and get back to you within one business day.
<p>
<br>
Regards,
<p>
Tom and Connie Quilter, Owners
<br />
<a href="http://ringsunique.com">ringsunique.com</a>
<?php }else{?>
<!-- primary page-openquote.php -->
<h1>Your Quote</h1>
<form onSubmit="return checkForm();" action="<?php bloginfo('url')?>/openquote/?word=thanks" method="POST" ><input type="hidden" value="rings@ringsunique.com" name="recipient"><input type="hidden" value="Rings Unique Quote Response" name="subject"><input type="hidden" value="" name="redirect"><table width="100%" cellspacing="3" cellpadding="0" border="0" align="left"><tbody><tr><td valign="top" align="right">The ring you selected:</td><td colspan="8"><b><?php $ringname=$_REQUEST['ring']; echo $ringname; ?></b></td></tr><tr><td valign="top" align="right" colspan="2"><input type="HIDDEN" value="artistic" name="ring collection"><input value="<?php echo $ringname?>" type="HIDDEN" value="1" name="ring_name"></td></tr><tr><td valign="top" align="right">Ring Size</td><td colspan="2"><input type="TEXT" size="5" name="ring_size" id="ring_size"></td></tr><tr><td valign="top" align="right">Your Name</td><td colspan="2"><input type="TEXT" size="40" name="yourname" id="yourname"></td></tr><tr><td valign="top" align="right">Mailing Address</td><td colspan="2"><input type="TEXT" size="40" name="address" id="address"></td></tr><tr><td valign="top" align="right">City</td><td><input type="TEXT" size="20" name="city" id="city"></td></tr><tr><td valign="top" align="right">State</td><td><select size="1" name="state" id="state"><option value="AL">AL</option><option value="AK">AK</option><option value="AZ">AZ</option><option value="AR">AR</option><option value="CA">CA</option><option value="CO">CO</option><option value="CT">CT</option><option value="DE">DE</option><option value="DC">DC</option><option value="FL">FL</option><option value="GA">GA</option><option value="HI">HI</option><option value="ID">ID</option><option value="IL">IL</option><option value="IN">IN</option><option value="IA">IA</option><option value="KS">KS</option><option value="KY">KY</option><option value="LA">LA</option><option value="ME">ME</option><option value="MD">MD</option><option value="MA">MA</option><option value="MI">MI</option><option value="MN">MN</option><option value="MS">MS</option><option value="MO">MO</option><option value="MT">MT</option><option value="NE">NE</option><option value="NV">NV</option><option value="NH">NH</option><option value="NJ">NJ</option><option value="NM">NM</option><option value="NY">NY</option><option value="NC">NC</option><option value="ND">ND</option><option value="OH">OH</option><option value="OK">OK</option><option value="OR">OR</option><option value="PA">PA</option><option value="PR">PR</option><option value="RI">RI</option><option value="SC">SC</option><option value="SD">SD</option><option value="TN">TN</option><option value="TX" selected="">TX</option><option value="UT">UT</option><option value="VT">VT</option><option value="VA">VA</option><option value="WA">WA</option><option value="WV">WV</option><option value="WI">WI</option><option value="WY">WY</option></select></td></tr><tr><td valign="top" align="right">Zip Code</td><td><input type="TEXT" size="10" id="zip" name="zip"></td></tr><tr><td valign="top" align="right">Phone</td><td><input type="TEXT" size="20" name="phone" id="phone"></td></tr><tr><td valign="top" align="right">Email Address</td><td colspan="6"><input type="TEXT" size="40" name="email" id="email"></td></tr><tr><td valign="top" align="right">Confirm Email Address</td><td colspan="6"><input type="TEXT" size="40" id="confirmemail" name="confirmemail"></td></tr><tr><td valign="top" align="left" colspan="2">Please enter any question or comment you may have for us.</td></tr><tr><td valign="top" align="left"></td><td colspan="8"><textarea cols="33" rows="5" name="comments"></textarea></td></tr><tr><td></td><td><input width="56" height="20" border="0" type="submit" id="sendemail" name="sendemail"></td></tr></tbody></table>
</form>
<?php if(have_posts()){
the_post();?>
<?php the_content(); ?>
<?php }; ?>
<?php };?>
</div><!-- ## main text ## -->
</div><!-- ## content ## -->
<?php get_footer(); ?>