phpinfo() Posted March 6, 2008 Share Posted March 6, 2008 Hello, I have some form fields that are being posted to a database. One field is a text field and the others are checkboxes. I can get the text to post to the database separately, but not at the same time. Like if there is text in the text field and a checkbox is checked, the data won't post. - The name has to be a certain name to work with my code, but it needs to be used on multiple fields. Is there a way where you can code so the form field name will equal the same as the other? Essentially have name2 = name 1 so on submit it acts the same and there are no conflicts? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 6, 2008 Share Posted March 6, 2008 use [] after the name so they are posted as an array <?php if (isset($_POST['sub'])) { foreach ($_POST['mytext'] as $text) { echo "$text<br/>"; } } ?> <form method='post'> <input type="text" name="mytext[]" value=""> <br> <input type="text" name="mytext[]" value=""> <br> <input type="text" name="mytext[]" value=""> <br> <input type="submit" name="sub" value="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
phpinfo() Posted March 6, 2008 Author Share Posted March 6, 2008 I get an array error when I do that. The fields are being submitted comma delimited, so I basically just want to be able to use the same name and have both the text filed and checkboxes submitted at the same time. Do I just need to duplicate my code, or is there a way to specify that a form field name = the same as the other form name? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 6, 2008 Share Posted March 6, 2008 Give us the stripped down HTML for your form as it was when you originally posted. Also give us the format you want the data to be in $_POST. The name has to be a certain name to work with my code, but it needs to be used on multiple fields. Why? Quote Link to comment Share on other sites More sharing options...
phpinfo() Posted March 6, 2008 Author Share Posted March 6, 2008 $ff = $_POST; if ($ff['FORMFIELDNAME']) { $variable = split(",",trim($ff['FORMFIELDNAME'])); $j=0; $k=0; for ($i=0;$i<count($variable);$i++) { <textarea name="FORMFIELDNAME" cols="30" rows="3" style="width:100%;" wrap="soft"></textarea> <input type="checkbox" name="FORMFIELDNAME" value="<?php echo htmlentities($variable) ?>" /> Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 6, 2008 Share Posted March 6, 2008 Why is it you can not change the name of either the textarea or the checkbox controls? Because you're going to have to. Quote Link to comment Share on other sites More sharing options...
phpinfo() Posted March 6, 2008 Author Share Posted March 6, 2008 I can just do this: if ($ff['FORMFIELDNAME1'] or $ff['FORMFIELDNAME2']) { But how could I incorporate FORMFIELDNAME2 in the code below:? $variable = split(",",trim($ff['FORMFIELDNAME1'])); Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted March 6, 2008 Share Posted March 6, 2008 I don't know, maybe with: $variable = split(",",trim($ff['FORMFIELDNAME1'] . $ff['FORMFIELDNAME2'])); It's hard to say because you haven't been very specific with what you're trying to accomplish here. Quote Link to comment Share on other sites More sharing options...
phpinfo() Posted March 6, 2008 Author Share Posted March 6, 2008 That works. Thanks!!! I was over thinking the && and or statements I guess. Thanks again. Quote Link to comment 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.