Allenph9 Posted March 7, 2012 Share Posted March 7, 2012 this is my code so far... <form action="<?php if ($_SESSION['reply_has_been_clicked'] != '1') { echo '';} elseif ($_SESSION['reply_has_been_clicked'] == '1') {echo 'thread_redirect.php';}?>" method='post'> <?php $_SESSION['current_thread'] = $the_thread_title . '.php'; if (($_SESSION['logged_in'] == '1') && (isset($_POST['reply_to_thread'])) && ($_SESSION['reply_has_been_clicked'] != '1')) { echo "<textarea name='thread_reply' style='resize:none;' cols='75' rows='10'>Enter your reply here...</textarea>"; echo "<br>"; $_SESSION['reply_has_been_clicked'] = '1'; } elseif (($_SESSION['logged_in'] != '1') && (isset($_POST['reply_to_thread']))) { $reply_echo = 'You need to be logged in!'; } ?> <input type='submit' name='reply_to_thread' value="Reply"> <?php echo $reply_echo; ?> so this works but it takes three button pushes to do the job. I can't think of anyother way to do it. help please! Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/ Share on other sites More sharing options...
batwimp Posted March 7, 2012 Share Posted March 7, 2012 You may find that this is easier to do using javascript. Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/#findComment-1324894 Share on other sites More sharing options...
Allenph9 Posted March 7, 2012 Author Share Posted March 7, 2012 I haven't done java script in a year or more... There has to be someway to do this in php...I just can't think of it. Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/#findComment-1324895 Share on other sites More sharing options...
batwimp Posted March 7, 2012 Share Posted March 7, 2012 In PHP, your page would need to be reloaded after each button press, which would get quite annoying. You could use session variables to keep track of button presses, I guess. But I would use javascript. Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/#findComment-1324896 Share on other sites More sharing options...
Allenph9 Posted March 7, 2012 Author Share Posted March 7, 2012 So I have tried to do this with php and failed. someonbe recommended java on another thread but...I havnt used java in a year or more and I have NEVER used it with html or php. So I was wondering if ya'll could help me come up with a script that would redirect only adter the button has been pushed twice... my attempt in php was... <form action="<?php if ($_SESSION['reply_has_been_clicked'] != '1') { echo '';} elseif ($_SESSION['reply_has_been_clicked'] == '1') {echo 'thread_redirect.php';}?>" method='post'> <?php $_SESSION['current_thread'] = $the_thread_title . '.php'; if (($_SESSION['logged_in'] == '1') && (isset($_POST['reply_to_thread'])) && ($_SESSION['reply_has_been_clicked'] != '1')) { echo "<textarea name='thread_reply' style='resize:none;' cols='75' rows='10'>Enter your reply here...</textarea>"; echo "<br>"; $_SESSION['reply_has_been_clicked'] = '1'; } elseif (($_SESSION['logged_in'] != '1') && (isset($_POST['reply_to_thread']))) { $reply_echo = 'You need to be logged in!'; } ?> that did the job but only after three button pushed. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/#findComment-1324900 Share on other sites More sharing options...
shaiang Posted March 7, 2012 Share Posted March 7, 2012 If I understand you correctly. You need to create a counter that starts with a zero value, then, on every click on the button, advance the counter by one... When the counter get to your desired number(2 in your case), then redirect... In javascript it's very easy, just catch the onclick event. And use preventDefault to prevent the form from submit the first time. Hope this helped you. Quote Link to comment https://forums.phpfreaks.com/topic/258473-redirect-after-button-is-pushed-twice/#findComment-1324946 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.