WordPress.org

Ready to get started?Download WordPress

Forums

Problem (rewrite?) with URI passed from a form (6 posts)

  1. Kadab
    Member
    Posted 4 years ago #

    Any help will be greatly appreciated, I am at a loss here...

    I have written a simple PHP registration form for my blog and inserted it in a file called optin.php (see below). I have placed the file in my theme directory and then added an empty page called Registration, using optin.php as a template (so all the content of the Registartion page comes from optin.php).

    So far so good, the form displays just fine. However I can't get it to redisplay with the confirmation part after I have submitted the form. I am receiving either a 404 Not Found or "article not found" messages, depending on the value I place in the action= atribute of my form. I have tried about everything...

    Here is my optin.php code (simplified for clarity) :

    <?php
    /**
     * @package WordPress
     * @subpackage My_Theme
     */
    /*
    Template Name: Optin
    */
    ?>
    <?php get_header(); ?>
    
    <div id="content" class="widecolumn">
       <div class="myClass">
          /* some text here */
          <?php
             if ($_POST['submit'])
             {
                /* here goes the part to display after form submission */
                /* I never managed to redisplay the page to show it... */
             }
             else
             {
                print '<form id="contact" method="post" onsubmit="return validateForm()" onreset="clearErrorMessages();" action="">';
                /* the rest of the HTML code for the form comes here */
                /* this part displays correctly                      */
                print '</form>';
             }
          ?>
       </div>
    </div>
    
    <?php get_sidebar(); ?>
    
    /* This is the javascript that does form validation with the     */
    /* onsubmit and onreset functions referenced in <form> above     */
    <script type="text/javascript" src="http://mysite.com/wp-content/themes/mytheme/script/contactform.js"></script>
    
    <?php get_footer(); ?>

    What should the value of action= be for the page to redisplay after the form has been submitted?

    The only rewrite rules I have is the standard WP stuff and I only use one .htaccess file (no other rewrite rules elsewhere):

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    I am stuck, please help!

  2. Kadab
    Member
    Posted 4 years ago #

    OK, just in case you had a similar problem, I found a solution:

    action="http://www.myblog.com?page_id=123">

    Using the page ID in the URL parameter string did the trick.

    It still would not work with the page name though, i.e.

    action="http://www.myblog.com/register/">

    results in the 404 Not Found error. I still don't know why - the value http://www.myblog.com/register/ is exactly what WordPress uses as the link for this page in my sidebar! If I request this URL from a browser, the page displays correctly. So the URL gets rewritten somehow in the process, I just can't figure where.

    Anyway, problem solved, case closed.

  3. Kadab
    Member
    Posted 4 years ago #

    Sorry, I thought it was fixed, but it's not!

    I am getting a totally erratic behavior, it worked for a while and now I am getting the same error messages as before - without changing anything in the confirguration or the code...

    Any experts out there?

    thanks!

  4. James Mehorter
    Member
    Posted 4 years ago #

    I am experiencing this same problem. Form setup on a template page (contact.php) will not redisplay the same page to process the form data / display confirmation. This is how I have always coded forms in php using something like action="<?=$_SERVER['PHP_SELF']?>" because of the RewriteRule with wp I have also tried <?=htmlentities($_SERVER['REQUEST_URI'])?> Which seems to of worked for this guy http://codingforums.com/showthread.php?t=163362 I've also tried placing the direct http:// link to the ?page_id, or using the_permalink() as the form action. Even setting action="" the form loads index.php?page_id=6 to process the form. Hence the page is blank after submission and the form html in contact.php is not displayed. I am quite confused :\

    Anyone have any insight here?

  5. Caali
    Member
    Posted 4 years ago #

    I'm also experiencing this problem. I've tried exactly the same methods as jamesmehorter. This drives me nuts! I just get redirected to the blog post page, even though the correct URL displays in the addressfield.

  6. Caali
    Member
    Posted 4 years ago #

    I think I've solved this problem. When I changed the names of my input elements it worked. I used input field names like "name" and "email". Simply changeing those solved my problem.

Topic Closed

This topic has been closed to new replies.

About this Topic