Disable button upon form submit - php

I made a BlackJack game using only php, and html of course for the layout. But what im trying to say is I need to only use PHP. So no javascript or something else.
My game is near completion, all that's left is the buttons.
I have 3 buttons, Start, Hit and the Stand button. These buttons work with forms, If you click Start it will submit a form where the player draws 2 cards and the dealer 1. Then if you click hit it submits a form where the page will give you 1 card. And by clicking Stand it lets the dealer play, drawing cards untill he hits => 17.
I hope you understand how my system works. (If not please tell me!)
Now when i start the program all buttons except Start needs to be disabled, when i submit the start form (Click the start button) it needs to disable the start button and enable all the others. I find this complicated to achieve since I've never done anything like this before without javascript.
I tried the following:
if (!isset($_SESSION["buttons"])){$_SESSION["buttons"]='disabled';}
This runs at the very start of the form, and in the buttons i echo the session out, so when i start it for the first time it disables all buttons, this works fine.
But when i click start, and run this:
if(FORM_start("Start")){
buttons();
}
And buttons(); being the following:
function buttons() {
$_SESSION["buttons"] = '';
}
It doesn't work the first time i click on Start, however if i click start again the other buttons get enabled suddenly.
So this way seems to work, only i need to press start twice, meaning i got 4 cards and the dealer 2.
Is there any way i can let it happen immediately or maybe there is some other way to disable/enable buttons using only PHP.
Thanks in advance!

Well, the easiest way to to do is setting up a numeric variable.
Lets say, it is $hands_played;
thus, the starting hand will be 0;
so, set your session to check is $hands_played = 0, if so, then add attribute disabled="disabled" to the button, if more than 0, don't.
but, to be honest, please use Javascript.

Related

Setting cookie through PHP when Contact Form 7 submited

I'm working on a landing page made with Bootstrap 4, Wordpress and Contact Form 7 plugin. In the page I have 4 buttons that when clicked show the same Contact Form 7 pop up form. I want them to:
Any of the 4 buttons clicked for the 1st time show the pop up with the form (already done).
When the form submited and any of the buttons clicked again (could be the same one) do not show the form, but start a download of PDF document.
I don't know how to design that better. I think that when the form is submited a cookie is set through PHP so I can check in each button if the form is done. Is it a good aproach? How should I set the cookie? Is there any other way?
The simple solution would be redirecting the user to the PDF right after the form submission - there is a simple guide on how yo can do it. That could enchance the UX, users wouldn't need to understand that they need to click the same button once again.
Also, it could be easier because you would obviously want to change something after the actual event of sending the data (no matter how you track it). For example, you will not only need to add teh URL to the PDF into the button, but change the text and maybe even the style of it to make it obvious to the user.
However if you'd like to make it complex way - you can try changing the link on the button of form submission or adding the download link (or "enabling" it), while disabling the submission button inside your form. Some examples on changing the link or showing/hiding contect can be found here and here - all using the jQuery, no extra PHP needed.

why is browser the back button not directing to the last viewed page?

I'm working on a site (reworking is probably a better word as I did not build it originally) and am encountering the following weird scenario:
Users go to a page which shows a list of current events. This is called "whats-on".
I have added a link to this page which takes users to a full event calendar for the month in a typical calendar format. This page is called "event-calendar". Once on the page they can also select which month they want to see and what type of events they are interested in.
Users can click on an event listed in any date to navigate to a page with the event details. (page is event-details with a query that pulls the relevant event.) I have added a back button to the page under the event listing which will return them to the calendar showing the month and search results they just looked at. No issues there - I am using PHP $_SERVER['HTTP_REFERER'] and that works perfectly.
Here is the issue - if I just did a back() or history.go(-1) link on that button, it takes the user all the way back to "whats-on". The same thing happens when you click the browser back button. It just skips over "event-calendar" entirely.
This apparently happens on the site under other scenarios such as business listings and searches.
Obviously I do not want that behavior - I want the back button to go to the previously viewed page like it should!!
I cannot think of anything in the code that would cause this, but the original site developers included a whole bunch of JQuery packages such as jQuery UI, and I'm wondering if something could be interfering with the default back button behavior. Is that even possible??
I guess what I want to know is there is any JQuery code that would change the behavior of the back button so I could hunt it down and kill it!!
Just looking for ideas as to where to start looking.
Apparently the only way I can get it to work is to manipulate the browser history using
history.pushState({}, '', 'event-calendar?<plus whatever query was used to pull the data>');
on the calendar page itself.
This seems to work but what a stupid workaround. Wish I could find the original problem.

Back button on pages with tabs

I'm doing a system where the pages are displayed by tabs (easytabs Plugin http://os.alfajango.com/easytabs/#tabs1-js)
At one point in the process it performs a query in the database, where we
see all the details of each item that appears. I'd like to go into the details of the item, click back to the (on broswer or a button) the page to return to the list displayed by the SQL query, just as with any single page, but currently it only displays a blank page.
I wonder how can I do to implement this solution using the layout tabs.
Thank you.
There are various ways to maintain UI state. One of them is using a "url hash". For example, you click tab 2, change the url hash to:
mypage.php#tab=2
Then if someone presses BACK and goes FORWARD, you use JavaScript to look at the URL has and determine that the user had previously pressed tab 2, so you run your own bit of code that triggers the same event.
I'm unfamiliar with "easytabs" so I'm sorry I can't help with the specific implementation details, but that's the gist of the technique.

How To Retrieve Variable From PHP to Flex

Okay - an easy answer for 99% of you. I have a custom class 'Users()'. In PHP I have all the values being populated correctly. When I go to Flash Builder - and do the test function - All the data comes back properly. However, when I click a button and refer to the lastResult property of the CallResponder - it comes up NULL the first time, and then if the button is clicked a second time it will return the correct result. What step am I missing? I had the same problem with something simliar last night and am getting BEYOND frustrated - especially since I know it is some SMALL detail I'm overlooking.
So just for clarification - lets say there is a button named button1
So button1's click handler:
1) Validates the text input properties
2) Asks the server if that user and password match
3) If they do - then I want it to grab all of that specific users info and put it into a User class. Again - when I test this function/method from within Flash Builder all the values come back as they should. It's just on the first button click they come back NULL...he second click they populate fine - I.E.-
Alert.show(currentUser.userFirstName); (First Click - NULL)
Alert.show(currentUser.userFirstName); (Second click - "Jack")
Any help is much appreciated!!! I am beating myself up over this and I know it is some simple, simple step I'm missing.
Thank you to all who take the time to help in advance!
-CS
To answer this simply, Flex is asynchronous... meaning the code you've executed in the next line may happen before your PHP code is done. The last result isn't populated yet when you've clicked the button the first time. The button clicking happens INSTANTLY, but the data needs a few seconds to come back. Likewise, the second time you click the button, you're going to get the last users info, not the current ones!!!
What you need to do is wait for the data to come back before you do anything. To do this, add an event listener to your service. It's called a "result" handler. There's a lot of good examples of this.
In the handler, go ahead and alert your popup with lastResult... or just, event.result. Should have what you're looking for.

Dividing a signup form into steps with jQuery

this thing is driving me nuts. I'm working on a personal "for my own fun" project involving a quite long sign up form.
What I want to do is to split the form into sections grouping the fields that are relevant for each step, and the ability to navigate back and forth before pressing Submit, which check marks or something to indicate which step is complete or not. I've found some examples around but they don't really fit into my design and can't get around to modify them exactly how I want.
I was aiming at something similar to the slide show in forum http://forum.xtreamer.net/, with the progress bar at the bottom and the clickable steps. I would like to do something like that but for the steps in a form.
Any ideas of where should I start? I tried to look at their code to see if they use a public or commercial (but third party) jquery plugin but no dice.
Anyone can recommend a tutorial or some resources?
Thanks!
I just designed something similar recently using jCarousel. it is a jquery plugin that allows you to easily scroll to certain positions, or ids on the page.
What we did was create a long horizontal page with several divs floated to the left. Each div contained a step or two, and had forward and back buttons at the bottom. When you click the next button on a particular step, it would quickly slide away and then next one would slid in
In addition to this, there were absolutely positioned buttons at the top that could take you to each step individually.
Here is an example of the individual navigation to go back and forth:
<div class="nav">
<a name="1" onclick="$(document).scrollTo('#1',3000);" style="float:left;">← Back</a>
<a name="3" onclick="$(document).scrollTo('#3',3000);" style="float:right;">Next →</a>
</div>
The #1 and #3 are ids of the prev, next steps -- this code being taken from step 2. 3000 is the milliseconds to scroll to each particular part of the form. 3 seconds is a bit long, but we had some animated images between the steps to make the form a little more fun!
Hope this helps :)
I think you trying develop a form in which user finish personal details and on click go to office details then on click go to address details and at last submit.
Try to use jquery show() hide()
There will be three divs.
when on click you show one div , hide other two divs.
there should be validation in each divs and on completing one details there should be some hidden flag to check that details is completed.
On the final details before submit you should check the flags for each div.
As you are trying to give option to come back to the first div , user can empty details of first and go to final. So this flag check is must
Should work !!!

Categories