Monday 15 February 2010

Check if variable name in Post array contains text using PHP -


I have a form that allows the user to add more fields to them. When the user does this, then two more fields appear (one for link text, another for link address). I use javascript to add a number to input names (like newLinkTitle1 + newLinkAddress1 , newLinkTitle2 + newLinkAddress2 I am, etc.).

  & lt; Input type = "text" value = "" name = "newLinkTitle" size = "50" /> & Lt; Input type = "text" value = "http: //" name = "new link order" size = "50" />   

I want to see if the use of variables in my mailing array is prefix newLinkTitle and then get associated with it newLinkAdress (forex ((stropes ($ _ POST, 'newLinkTitle') $ currentNewLinkTitle) {/ / Check if newLinkTitle exists $ num = substr ($ Current Newlly Title, 12); // "newlinktitle" $ currentLinkAddress = $ _POST ['newLinkAddress'. $ Num] Get the number after // update query}

The correct approach will be to name the field as an array: newLinkTitle [] and NewLinkAddress [] :

  input type = "text" value = "" name = "new linkitit []" size = "50" />    

then using your JS code Add only one of the two fields with the same name ( newLinkTitle [] and newLinkAddress [] ). And in PHP, just do something like this:

  foreach ($ _Post ['newLinkTitle'] as $ key = & gt; $ val) $ $ currentNewLinkTitle = $ val; $ CurrentNewLinkAddress = $ _POST ['newLinkAddress'] [$ K]; // to save the DB)   

Do not forget to avoid price before saving the DB

No comments:

Post a Comment