Page 1 of 1

If Form Was Submitted

Posted: Tue Sep 13, 2011 1:28 pm
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

Re: If Form Was Submitted

Posted: Tue Sep 13, 2011 6:00 pm
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}

Re: If Form Was Submitted

Posted: Tue Sep 13, 2011 8:19 pm
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.

Re: If Form Was Submitted

Posted: Wed Sep 14, 2011 3:39 am
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