php form to redirect to another URL on successful submission

Discussion in 'PHP' started by sleuth1, Feb 28, 2013.

  1. #1
    Hi I have a very complex php directory submission form I have just included a sample of it here it is very long, what i want to do is on submitting a website the user is taken to another webpage rather than as it is a script displays " your website has been submitted" and the user stays on that original submission page, help appreciated. Let me know if more of the code is required.


    <form action="{'/webmaster/saveNewWebsite'|url}" method="post" id="itemForm">
    <input type="hidden" name="siteType" value="{$siteType}"/>
    
    Code (markup):
    toward the end of the form this is how it is configured
       
        <div class="form">
        <label class="title">{'webmasterSubmitWebsite_backlink_url'|lang}</label>
        <div class="infos"><input type="text" class="input_text_large" name="returnBond" value="" /></div>
        </div>
       
        {if $setting.backLinkHtmlCode1Enabled}
        <div class="form">
        <label class="title">{'webmasterSubmitWebsite_backlink_html1'|lang}</label>
        <div class="infos"><textarea class="textarea_return" name="backLinkCode1" cols="50" rows="5">&lt;a href="{if $setting.backLinkHtmlCode1Url}{$setting.backLinkHtmlCode1Url|htmlspecialchars}{else}{$setting.siteRootUrl|htmlspecialchars}{/if}"&gt;{if $setting.backLinkHtmlCode1Text}{$setting.backLinkHtmlCode1Text|htmlspecialchars}{else}{$setting.siteTitle|htmlspecialchars}{/if}&lt;/a&gt;</textarea><img src="{"/templates/$templateName/images/icone_info.gif"|resurl}" alt="" class="aide_description" title="{'webmasterSubmitWebsite_backlink_html_tooltip'|lang}"></div>
        </div>
        {/if}
       
        {if $setting.backLinkHtmlCode2Enabled}
        <div class="form">
        <label class="title">{'webmasterSubmitWebsite_backlink_html2'|lang}</label>
        <div class="infos"><textarea class="textarea_return" name="backLinkCode2" cols="50" rows="5"></textarea><img src="{"/templates/$templateName/images/icone_info.gif"|resurl}" alt="" class="aide_description" title="{'webmasterSubmitWebsite_backlink_html_tooltip'|lang}"></div>
        </div>
        {/if}
    </fieldset>
     
    <div class="title_h">
    <h2>{'webmasterSubmitWebsite_step'|lang} {counter}/{$totalSteps} &nbsp;&nbsp;{'webmasterSubmitWebsite_submit_website'|lang}</h2>
    </div>
    <fieldset class="column_in">
        {if $setting.newsletterEnabled}
        <div class="form">
        <label class="title">{'webmasterSubmitWebsite_subscribe_newsletter'|lang}</label>
        <div class="infos"><input type="checkbox" name="newsletterActive" value="1"></div>
        </div>
        {/if}
       
        {if $setting.captchaEnabledOnSiteInscription && (empty($session.role) || $session.role != "webmaster")}
        <div class="form">
        <label class="title">{'webmasterSubmitWebsite_security_code'|lang} <span class="text_color_mandatory">*</span></label>
        <div class="infos captchaCode"></div>
        </div>
        {/if}
       
        <div class="form">
        <label class="title">&nbsp;</label>
        <div class="infos_terms">{'webmasterSubmitWebsite_terms_use_desc'|lang} <a href="{'/info/useCondition'|url}" class="link_small_underline" target="_blank">{'webmasterSubmitWebsite_read_terms'|lang}</a></div>
        </div>
       
        <div class="form">
        <label class="title">&nbsp;</label>
        <div class="infos"><div id="siteLoader" style="display:none;"> {'webmasterSubmitWebsite_checking'|lang} <img src="{"/templates/$templateName/images/loader.gif"|resurl}"></div> <input type="submit" class="button" value="{'webmasterSubmitWebsite_button_submit'|lang}" /></div>
        </div>
    </fieldset>
     
     
    </div>
    </form>
     
    {include file="includes/footer.tpl"}
    Code (markup):
    the end of form this is how it is configured
     
    sleuth1, Feb 28, 2013 IP
  2. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #2
    In PHP, when the form is saved:

    header
    (
    "Location: http://www.example.com/"
    );
     
    kajakske, Feb 28, 2013 IP
  3. sleuth1

    sleuth1 Well-Known Member

    Messages:
    261
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Thanks, forgive my ignorance but where exactly would that piece of code be placed
     
    sleuth1, Feb 28, 2013 IP
  4. kajakske

    kajakske Well-Known Member

    Messages:
    139
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    165
    #4
    That would be in this url: /webmaster/saveNewWebsite

    You didn't supply that code, so can't say where exactly ...
     
    kajakske, Feb 28, 2013 IP
  5. Forbidd3n

    Forbidd3n Well-Known Member

    Messages:
    262
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    sleuth1,

    An example would be to post the form to itself and do error checking on the fields you want required or other formats. After that then redirect to the final page. Example below...

    //---- page.php
    <?php
    $error = false;
    if($_POST){
    if(!empty($_POST['name'])){
    header("Location: thanks_page.php");
    exit;
    }else{
    $error = true;
    }
    }
    ?>

    <form action="page.php" method="post">
    Name: <input type="text" name="name" id="name" value="">
    <?php if($error){ print 'Name is required.'; } ?>
    <input type="submit" name="send" id="send" value="Send Name">
    </form>


    //----- thanks_page.php

    Thank you for your submission


    Let me know if you have any questions.
     
    Forbidd3n, Mar 4, 2013 IP
  6. VideoWhisper.com

    VideoWhisper.com Well-Known Member

    Messages:
    330
    Likes Received:
    6
    Best Answers:
    2
    Trophy Points:
    113
    Digital Goods:
    2
    #6
    PHP header only works if you did not generate page output, yet.
    If you need to redirect after some output, use javascript:
    <script>document.location = "new url here"</script>
     
    VideoWhisper.com, Mar 11, 2013 IP