If Form Was Submitted

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Aleeious
Posts: 55
Joined: Tue Sep 13, 2011 1:22 pm

If Form Was Submitted

Post by Aleeious »

I am working on the registration page for my game. I am using smarty to create the different pages that will be displayed throughout the game. I would like to create script say "register.php" that redirects to itself, and depending on weither this is the first time the user is viewing the form or submitting it it does something different. So for example the first time, the registration form is shown and then when the form is submitted the same page submits the registration info to the mysql server. This is the way the Wordpress script handles logins and registrations and i would like to mimic it. Any assistance would be greatly appreciated.

Sincerely,

Aleeious
User avatar
Torniquet
Posts: 869
Joined: Sun Aug 02, 2009 6:18 am

Re: If Form Was Submitted

Post by Torniquet »

There are 2 ways going about it.

firstly, you could use 2 templates.

Code: Select all

if(isset($_POST['submit']))
{
    $page = "registered";
}
else
{
    $page = "register";
}

$smarty->display($page . ".tpl");
 
secondly, you could handle it inside a single template.

Code: Select all

{if $smarty.post.submit}

show registered content

{else}

show registration form

{/if}
New Site Coming Soon! Stay tuned :D
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: If Form Was Submitted

Post by Xaleph »

Yeah that works. But it can be done differently, you can post different types of hidden fields, so the first form has a hidden field called form-1, the second form-2 and so on, and so on. That way you can both check the information, if the form was submitted but also if there`s more to it then 1 form, which sometimes is the case ( more then 1 form that is.. )

Anyway, works the same way as Torni told you, except you don`t check if $_POST[''submit] rather, $_POST['step-1'] et cetera.
Aleeious
Posts: 55
Joined: Tue Sep 13, 2011 1:22 pm

Re: If Form Was Submitted

Post by Aleeious »

Thanks, your code was easy to follow and understand. I hope to add this code soon to my registration script and maybe start accepting registrations for character name reservations ;).

Sincerely,

Aleeious
Post Reply

Return to “Beginner Help and Support”