Title: Triggering form action on same page with the plugin insert php code snippet
Last modified: March 31, 2019

---

# Triggering form action on same page with the plugin insert php code snippet

 *  [halohtlo](https://wordpress.org/support/users/halohtlo/)
 * (@halohtlo)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/)
 * 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.
    -  This topic was modified 7 years, 2 months ago by [halohtlo](https://wordpress.org/support/users/halohtlo/).
    -  This topic was modified 7 years, 2 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).

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

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11376191)
 * 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](https://wordpress.org/support/users/halohtlo/)
 * (@halohtlo)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11376347)
 * 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](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11376549)
 * 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](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11377003)
 * 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](https://wordpress.org/support/users/halohtlo/)
 * (@halohtlo)
 * [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11379691)
 * 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.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 3 participants
 * Last reply from: [halohtlo](https://wordpress.org/support/users/halohtlo/)
 * Last activity: [7 years, 2 months ago](https://wordpress.org/support/topic/triggering-form-action-on-same-page-with-the-plugin-insert-php-code-snippet/#post-11379691)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
