Jump to content

Add to cart with no redirect?


Recommended Posts

Hi Guys,

 

I'm programming up some code and I need a way to simply add selected domain names to my cart without actually taking me to the cart page...

 

I'm planning on using some form of onclick code but currently the code is a form which submits to <form method="post" action="{$systemsslurl}cart.php?a=add&domain=register">

 

Is there a way to just add the names to the cart then do the configuration?

Link to comment
Share on other sites

If you do an ajax submit to the following url, the domain will get added to the cart. If you look at the results it still gets redirected to the config page but the domain is added to the cart and can be configured later.

https://yourdomain.com/cart.php?ajax=1&a=add&domain=register&domains[]=domainname.com&domainsregperiod[domainname.com]=1

Link to comment
Share on other sites

Hey,

 

I've added this:

 

{if $result.status eq "available"}<a href="https://secure.totallytech.it/cart.php?ajax=1&a=add&domain=register&domains[]={$result.domain}&domainsregperiod[{$result.domain}]=1" /><img src="templates/dj/add.jpg" /></a>{else}X{/if}

 

However when I click on the add image (the link displays correctly and is shown fine but it still just loads cart.php - nothing seems different...

 

What have I missed?

Link to comment
Share on other sites

I thought you were asking how to do this via javascript, you could do a jQuery post to the url I gave you as long as the page is hosted within your whmcs instance .

 

What are you trying to have happen when a user clicks add, where did you want them redirected to?

Link to comment
Share on other sites

ok, I've now rewritten my code...

 

<script type="application/javascript">
function submitForm() {
   $.ajax({type:'POST', url: 'https://secure.totallytech.it/cart.php?ajax=1&a=add&domain=register', data:$('#add-form').serialize(), success: function(response) {
       $('#add-form').find('.form_result').html(response);
   }});

   return false;
}
</script> 

 

plus my main page code

<form method="post" id="add-form"  onsubmit="return submitForm();">
<table width="700" border="0" cellspacing="5" cellpadding="0">
   {foreach from=$availabilityresults key=num item=result}
   <input type="hidden" name="domain" value="{$result.domain}" />
   <tr style="border-bottom: #333 1px solid;">
   <td rowspan="2">{if $result.status eq "available"}<img src="templates/dj/yes.jpg" />{else}<img src="templates/dj/no.jpg" />{/if}</td>
   {if $result.status eq "available"}<td style="color:#339933;" />{$result.domain|replace:$domain:''}</td>{else}<td style="color:#cc0000;" />{$result.domain|replace:$domain:''}</td>{/if}
   <td rowspan="2">{$result.domain}</td>
   <td rowspan="2">{if $result.status eq "unavailable"}<img src="templates/dj/transfer.jpg" />{else}
   <select name="domainsregperiod[{$result.domain}]">
   {foreach key=period item=regoption from=$result.regoptions}
   	<option value="{$period}">{$period} {$LANG.orderyears} @ {$regoption.register}</option>
   {/foreach}
   </select>
   {/if}</td>
   <td rowspan="2">{if $result.status eq "available"}
   <input type="image" src="templates/dj/add-basket.png" /> <div class="form_result"> </div>
   {else}X{/if}</td>
 </tr>
 <tr>
   <td>{if $result.status eq "available"}Available{else}Taken{/if}</td>
 </tr>
 <tr><td colspan="8" style="height:1px; background-color:#999;"></td></tr>
 {/foreach}
</table>
</form>

 

Nothing is added to the cart though... I've checked the source and its showing the correct info -

 

<form method="post" id="add-form" onsubmit="return submitForm();">

<input type="hidden" name="token" value="c36dbb441a74d2f57c7e3484db9c7613f5f0213d" />

 

<table width="700" border="0" cellspacing="5" cellpadding="0">

<input type="hidden" name="domain" value="drewjohnstone.uk" />

<tr style="border-bottom: #333 1px solid;">

<td rowspan="2"><img src="templates/dj/yes.jpg" /></td>

<td style="color:#339933;" />.uk</td> <td rowspan="2">drewjohnstone.uk</td>

<td rowspan="2"> <select name="domainsregperiod[drewjohnstone.uk]">

<option value="1">1 Year/s @ £4.55</option>

<option value="2">2 Year/s @ £9.10</option>

<option value="3">3 Year/s @ £13.65</option>

<option value="4">4 Year/s @ £18.20</option>

<option value="5">5 Year/s @ £22.75</option>

<option value="6">6 Year/s @ £27.30</option>

<option value="7">7 Year/s @ £31.85</option>

<option value="8">8 Year/s @ £36.40</option>

<option value="9">9 Year/s @ £40.95</option>

<option value="10">10 Year/s @ £45.50</option>

</select>

</td>

<td rowspan="2"> <input type="image" src="templates/dj/add-basket.png" /> <div class="form_result"> </div>

</td>

</tr>

<tr>

<td>Available</td>

</tr>

</table>

 

What have I missed?

Edited by totallytech
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated