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
https://forums.phpfreaks.com/topic/94650-php-duplicate-form-name-submit/
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>

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?

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?

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

 

 

 

Archived

This topic is now archived and is closed to further replies.

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