suttercain Posted May 5, 2007 Share Posted May 5, 2007 Hi guys, I am running the following code: <?php //voting system if ($vbulletin->userinfo['usergroupid'] == '6' || $vbulletin->userinfo['usergroupid'] == '9' && !isset($_POST['submit'])) { voteNow(); } elseif (isset($_POST['submit'])) { echo "Thank you for voting!"; } else { echo "Please Login to vote"; } function voteNow() { ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"> <select> <option>5</option> <option>4</option> <option>3</option> <option>2</option> <option>1</option> </select> <input type="submit" name="submit" value="Vote"> </form> <?php } ?> I have a small form. If the submit button has not been pressed, it echos the form. I can't get it to not echo the form if the submit button has been pressed though... Do I have it set up wrong? Thanks Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/ Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 So u dont want to echo the form after submission. Am i right. Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245927 Share on other sites More sharing options...
suttercain Posted May 5, 2007 Author Share Posted May 5, 2007 You are correct. Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245929 Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 Simple redirect the page after submit to a page like success.php or thankyou.php by using header: header('Location:thankyou.php'); Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245931 Share on other sites More sharing options...
suttercain Posted May 5, 2007 Author Share Posted May 5, 2007 I don't want a redirect though. This is a self procsessing form... they need to remain on the same page. <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"> Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245934 Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 U r using action="<?php $_SERVER['PHP_SELF'] ?>" it mean that it process the from in sam page, Then how it possible that without redirect u will not see the same page. Bcoz when u submit the form, code process on the same page then difenetly it will show u the page agian. For this issue just redirect the whole page then give the back button using js or something To come back to prev page. Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245939 Share on other sites More sharing options...
suttercain Posted May 5, 2007 Author Share Posted May 5, 2007 I have done it this way numerous times. That is why you use the if statement and the else statement. Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245941 Share on other sites More sharing options...
suttercain Posted May 5, 2007 Author Share Posted May 5, 2007 Got it working, here is how I did it in case this helps someone else in the future: if ($vbulletin->userinfo['usergroupid'] == '1' || $vbulletin->userinfo['usergroupid'] == '9') { if (!isset($_POST['submit'])) { voteNow(); } else { voted (); } } else { echo "Login to Vote"; } function voteNow() { ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post"> <select> <option>5</option> <option>4</option> <option>3</option> <option>2</option> <option>1</option> </select> <input type="submit" name="submit" value="Vote"> </form> <?php } function voted() { echo "Thank you for voting!"; } ?> Processes the form without leaving the page and based on the if statement echoes the desired statement or function. Peace Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245943 Share on other sites More sharing options...
mmarif4u Posted May 5, 2007 Share Posted May 5, 2007 glad that u have solve it. Link to comment https://forums.phpfreaks.com/topic/50090-solved-cant-get-the-elseif-statement-to-work-for-me/#findComment-245948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.