Results 1 to 10 of 16

Hybrid View

  1. #1
    Join Date
    May 2008
    Posts
    31
    Plugin Contributions
    0

    Default Problem redirecting upon form submission

    I'm having trouble redirecting after having a user fill out a form. In order to test functionality of my redirect, I've created a simple form where a user enters an email address and a name. The form calls itself to do a simplified validation, and then gets redirected to another page. Problem is...the page will not redirect. As you can see from the enclosed code, I've tried both methods of redirection using header(location: URL) and zen_redirect(URL). Right now, the redirection does not occur and results in my form main_page being blank.

    My form resides in my template in define_my_test_page.php.

    Code:
    <?
    $message = "";
    $emailclass = "basictext";
    $username = "";
    
    if ($_POST['process'] == 1) {
    
    $pattern = '/.*@.*\..*/';
    $email = $_POST['email'];
    $urlname = urlencode($$_POST['username']);
    
    if (preg_match($pattern, $_POST['email']) > 0) {
    // Here's where you would store
    // the data in a database...
    header("location: index.php?main_page=my_product_home");
    //zen_redirect("index.php?main_page=my_product_home");
    
    }
    $message = "Please enter a valid email address.";
    $username = $_POST['name'];
    $emailclass = "errortext";
    }
    ?>
    
    <html>
    <style>
    .basictext {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px; color:#000066;
    }
    .errortext {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px; color:#C00000; font-weight: bold;
    }
    </style>
    <body>
    <form action="index.php?main_page=my_test_page" method="post">
    <? if ($message != "") {
    print '<span class="errortext">'.
    $message."<span><br>\n";
    }
    ?>
    <span class="<?print $emailclass; ?>">
    Email address:</span>
    <input name="email" type="text"
    class="<? print $emailclass; ?>"><br>
    
    <span class="basictext">Your name:</span>
    <input name="name" type="text" class="basictext"
    value="<?print $username; ?>"><br>
    <input type="hidden" name="process" value="1">
    <input type="submit" name="Button1" value="Sign up!">
    </form>
    </body></html>
    Thanks for any help,

    Dustin

  2. #2
    Join Date
    May 2008
    Posts
    31
    Plugin Contributions
    0

    Default Re: Problem redirecting upon form submission

    Clarification: Even when I reduce the code in my define_my_test_page.php to the following, the redirect does not work. When I go to index.php?main_page=my_test_page, the main page is blank except for the header name. Obviously, redirects in this manner do not work.

    Any suggestions for how to call a redirect from within define pages? I'm guessing I'm missing something simple.

    Code:
    <?php
    zen_redirect("index.php?main_page=my_product_home");
    ?>

  3. #3
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Problem redirecting upon form submission

    Have you tried ...?
    ?php
    zen_redirect("my_product_home");
    ?>
    Re: your first post, short tags are really not recommended.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  4. #4
    Join Date
    May 2008
    Posts
    31
    Plugin Contributions
    0

    Default Re: Problem redirecting upon form submission

    Thanks for your reply.

    Unfortunately, no luck with the change you recommended. Per your second recommendation, once I can get the redirect functionality working, I will make the change to get rid of my short tags.

    I have attached a small snapshot of what my screen looks like when I load index.php?main_page=my_test_page. As you can see, the header title "my_test_page" shows up but is blank underneath.
    Attached Images Attached Images  

  5. #5
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: Problem redirecting upon form submission

    FAQ on troubleshooting blank pages (or blank "parts of pages"): https://www.zen-cart.com/tutorials/index.php?article=82
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    May 2008
    Posts
    31
    Plugin Contributions
    0

    Default Re: Problem redirecting upon form submission

    Thanks DrByte. I'll download the error debugging utility and give it a try. In the meantime, could you (or anybody else) give me the proper way to redirect from within a define page?

    Right now, all I have on my define redirect page is:

    Code:
    <?php zen_redirect("index.php?main_page=my_product_home"); ?>

    I've eliminated anything extraneous to get the redirect functionality working.

    Other than the usage of short tags, I am pretty sure this function call is written correctly. When I place the same function call in /modules/pages/my_test_page/header_php.php the redirect works fine. It seems to me that I simply don't know the correct way to redirect from within the define page, rather than the header. I've successfully written php scripts and redirected on other projects using header(location: $url) but something is different in this case.


    Thanks again for all your help.

    Dustin
    Last edited by dgsignal; 26 Jun 2008 at 02:24 AM. Reason: spelling error

 

 

Similar Threads

  1. v153 Add custom form submission data access on Admin backend
    By fahadali in forum Customization from the Admin
    Replies: 9
    Last Post: 12 Feb 2016, 02:59 AM
  2. Odd extra elements in URL after form submission
    By gjh42 in forum Contribution-Writing Guidelines
    Replies: 5
    Last Post: 28 Aug 2014, 04:40 PM
  3. Retaining data in form submission
    By ethangreen in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 2 Jun 2009, 08:53 PM
  4. Simple Submission Form in EZ-Pages
    By pensive612 in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 18 Apr 2007, 10:46 PM
  5. required file on a submission form
    By iano in forum General Questions
    Replies: 1
    Last Post: 14 Oct 2006, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg