Skip to content Skip to sidebar Skip to footer

Php Html Show Button Properties

I would like to be able to get as many properties from a button to show as I can. The button:

Solution 1:

One possible way, without using javascript would be to store a copy of the data in the name of the element:

<input name="Accept" type="submit" class="button" id="Accept" value="Accept" />

becomes:

<input name="Accept.submit.button.Accept" type="submit" class="button" id="Accept" value="Accept" />

You can get the value from your $_POST array. For the rest of the properties, just split up the key of the element using explode().


Solution 2:

There is no way how to get properties of HTML element by normal HTML behavior - but you can use JavaScript function that handles "onSubmit" form event by which you can send all you need.


Solution 3:

There is no way to submit properties of an input besides the name and value, however you can have hidden inputs on the form with whatever information you want, and you can even create them or populate them dynamically in the button's onclick even or the form's onsubmit event.

As another option I would stuff in the information in the button's value in JSON form, since the button's value usually anyway serves no purpose.

And if you are really out for ideas then you can stuff the info in the query string of the url in the action attribute of the form, and then get the info by checking the GET array (however if the form method is get instead of post then the values might get overwritten!)

But if yout problem is only that you need a way to distinguish between many buttons, then just have a different name or value for each of them, and this is probably the only reason why buttons have names and values.


Regarding andrejd's answer please note that while you can use the onSubmit function to to submit with Ajax and then return false to cancel the default submit, please note that the following problems exist with that approach:

1) That the onSubmit function doesn't know which button was pressed, however you can instead use the button's onClick event, but you will have to bind to every submit button on the form (you can do this much easier with jquery etc.)

2) Since Ajax does not affect the page content so ypu will refresh it on your own or navigate the page on your own, the latter can be done using "location.href"

3) If you are submitting files you will have a hard time doing it with ajax, you can try the use the jquery fileupload plugin.

4) Ajax is restricted to the same origin (something tgat form submittion isn't), you can try to workaround using JSONP.

5) Ajax will not work if the client doesn't have JavaScript (such as some mobile phones or some text browsers such as linux browsers) or has disabled JavaScript or is using an older browser, and in general it is not recommended to rely solely on Ajax but instead at least provide an alternative for these cases.


For problems 2-4 you can aldo solve them by having the Ajax just the extra content and then return true to let the default submission submit the form.


Post a Comment for "Php Html Show Button Properties"