Jump to content

PHP Duplicate Form Name Submit??


phpinfo()

Recommended Posts

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?

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

$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) ?>" />

 

 

 

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.