WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Submitting a form to itself (4 posts)

  1. Fahim Mahmood
    Member
    Posted 2 years ago #

    I'm facing a problem i have following form with just a Submit button on a Template Page of WordPress blog:

    <form action="<?php echo get_permalink(); ?>&pid=[page_id]&action=add" method="get">
    <input type="submit" value="Add to Cart" />
    
                              </form>

    on a Template Page i want to submit it to the same page with some values through the URL but reason whenever i submit it it sends me back to homepage i.e. index.php of the template.

  2. Sandip Patil
    Member
    Posted 2 years ago #

    1. Make the form method as post
    2. Remove the parameters from action
    3. Pass the parameters through hidden fields

    Check below code :

    if(issset($_POST['save_data'])){
    // Do operations here...
    }
    
    <form name="frm_add_cart" action="<?php echo get_permalink(); ?> method="post">
    <input type="hidden" name="pid" value = "[page_id]" />
    <input type="hidden" name="action" value = "add" />
    <input type="submit" name="save_data" value="Add to Cart" />
    </form>
  3. Fahim Mahmood
    Member
    Posted 2 years ago #

    Sandip thanks for the reply Its working now :D!!

  4. Fahim Mahmood
    Member
    Posted 2 years ago #

    This is resolved now :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.