• halohtlo

    (@halohtlo)


    Hello there, so I’ve the following problems:

    I’m coding a php shopping cart and currently using a theme that does not support custom page templates so I have to use the plugin ” insert php code snippet ” which works fine, I just insert my code there and copy->paste the shortcode in my page.
    All good so far but here comes the problem:
    In order to add products to the cart my form action triggers the following code:

    <form method="post" action="CartDisplay.php?action=add&code=<?php echo $product_array[$key]["code"]; ?>">
    </form>

    This works perfectly on my local server however here it cant target the ” CartDisplay.php ” file because it isn’t on the server of my website and I’m currently using a plugin to add the php code. When I upload it on the server it still won’t get recognized. ( Maybe I fail at pathing correctly? )

    So, when I click the button ” Add to cart ” I get redirected to a 404 page, even though I’m not using any reserved keywords by wordpress like “name”. I’ve them all with a prefix.

    If you need more of my code I’d be glad to share it, just didn’t want to make this post look too big and messy.
    Any ideas? I’d really appreciate your help. Have a good day folks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Joy

    (@joyously)

    You have experienced why your shopping cart plugin needs to encapsulate all of the functionality, instead of relying on other plugins or a theme. It should provide the shortcode for the form, or an ajax way of adding to the cart. It should not be dependent on any theme or the user putting PHP into their page content.

    Thread Starter halohtlo

    (@halohtlo)

    Sorry, I didn’t really understand your answer. I don’t have a shopping cart plugin, it’s custom coded, I have a plugin that allows me to inject php code into pages because my theme doesn’t support page templates, and therefore the problem with form actions.

    Moderator bcworkz

    (@bcworkz)

    If CartDisplay.php is not on your website’s server, any form that submits to that file cannot possibly work. Either copy the file and its dependencies to the server or refactor how your form works so it does not need CartDisplay.php to function. By using Ajax techniques for example.

    BTW, relative paths in WP are unreliable. If you are going to submit to CartDisplay.php on the server, I urge you to use a complete, absolute URL in your form’s action attribute.

    Joy

    (@joyously)

    You said you were coding a shopping cart. I assumed you knew enough to put the code into a plugin. All I’m saying is that all of the pieces to it should be in one plugin, and it will work a lot better that way.

    Thread Starter halohtlo

    (@halohtlo)

    Thank you all for the help.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Triggering form action on same page with the plugin insert php code snippet’ is closed to new replies.