Jump to content

Populate custom field via URL?


balebond

Recommended Posts

Does anyone know if there is a way to populate a custom product field via url like you can with variables like language and promocode?

 

I know I can do this for example:

 

cart.php?a=add&pid=1&promocode=TEST

 

 

Is there anyway to accomplish it for custom fields... something like this?:

 

cart.php?a=add&pid=1&customfield[20]=sometext

Link to comment
Share on other sites

  • 3 weeks later...
  • 10 months later...
  • 3 months later...

You can do it with a little jQuery magic...

 

Put this in any template that you want to populate a custom field:

{literal}
<script type="text/javascript">
$(document).ready(function(){
   $("input[name=customfield\[CUSTOMFIELD\]]").val("{literal}{$smarty.get.VAR}{/literal}");
});
</script>
{/literal}

Change CUSTOMFIELD to the numeric ID of the field, and change VAR to the name of the variable passed in the URL.

 

Works like a charm, I use it in many areas of my site. It can also be accomplished using actionhooks, however it's a bit more complicated.

Link to comment
Share on other sites

That's what I get for not actually testing code before posting it. There was a typo in the {literal}s. This one definately works because I just tested it. :)

 

This code works:

 

{literal}
<script type="text/javascript">
$(document).ready(function(){
   $("input[name=customfield\[CUSTOMFIELD\]]").val("{/literal}{$smarty.get.VAR}{literal}");
});
</script>  
{/literal}

Change CUSTOMFIELD to the numeric ID of the field, and change VAR to the name of the variable passed in the URL.

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