dadamssg87 Posted October 3, 2011 Share Posted October 3, 2011 So i'm trying to create a receipt creation/editing form. One where i can add individual items to it. Each item would have like 2 or 3 form inputs(name, price, quantity). Ideally, i would like just like to have javascript handle this but in the event a user has javascript disabled i'd still like it to function. How could i add a link/button that would capture the $_POST values of the existing form inputs? You can't have multiple submit buttons for different form actions to the same form, can you? Or is this type of a thing only suited to be handled by javascript? Quote Link to comment https://forums.phpfreaks.com/topic/248342-dynamically-adding-form-input-fields/ Share on other sites More sharing options...
SparK_BR Posted October 6, 2011 Share Posted October 6, 2011 you can give a name to the submit button and then check isset($_POST['name']); to see what action to take, your target script would be a delegator, just delivering the message to the right script so you can either redraw the screen with more itens or add the itens to the database (phpMyAdmin does that) Quote Link to comment https://forums.phpfreaks.com/topic/248342-dynamically-adding-form-input-fields/#findComment-1276417 Share on other sites More sharing options...
AyKay47 Posted October 6, 2011 Share Posted October 6, 2011 if you set an onsubmit javascript event handler on the form, and tell it to return false onsubmit.. this will ensure that if the user has js enabled.. the onsubmit event will handle it, however if they do not have js enabled.. PHP will handle it.. what the "return false" does is prohibits the default action of the form..(submit form via PHP, refresh page) and has the js function that you provide handle the form instead. <form onsubmit='somfunc();return false'> <input type='text' name='whatever' id='whatever'> <input type='submit' name='whatever1' id='whatever1' </form> some people like to set the onclick event on the submit button, however this is a common mistake, since the user also has the option of submitting the form by pressing enter.. Quote Link to comment https://forums.phpfreaks.com/topic/248342-dynamically-adding-form-input-fields/#findComment-1276435 Share on other sites More sharing options...
RobertP Posted October 6, 2011 Share Posted October 6, 2011 i don't know if this helps, but on my cms, i have it set up when the users changes his password, he needs to provide his current password, and the current password box will appear only if they try to change the new password field. i use onchange .. Quote Link to comment https://forums.phpfreaks.com/topic/248342-dynamically-adding-form-input-fields/#findComment-1276617 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.