Jump to content

dynamically adding form input fields


dadamssg87

Recommended Posts

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.