简体   繁体   中英

How to post multiple input fields

I am a new to this type of coding so I was wondering if someone could help me.

Here's what I want to achieve, an input field where the user can enter text and have another text appended to this. So for example, when the user enters text eg "My Name!!", upon posting there would be another hidden text appended to this, so the server would receive "Hidden Text!","My Name!!".

Here's an image explaining this in an easier way.

在此处输入图片说明

Here is my code so far..

        <form method="post" action="jumpin.php">
            <label>Desired Username:</label>

            <div>
                <label id='labletext'><?php echo $_SESSION['user_name_custom']; ?></label>
                <input type="text" id="userid" name="userid" />
                <input type="submit" value="Check" id="jumpin" />
            </div>
<script>
    $('#userid').keyup(function(){
    $(this).css('color','#000');   
    });
    $('#userid').blur(function(){
    var value = $('#labletext').text()+$(this).val();
    $(this).val(value);
    });
</script> 
        </form>

This code doesn't seem to be working, all the server receives is the text the user submitted and not the "labletext".

You can use a hidden input field.

<input type="hidden" name="extra_label" value="<?php echo $_SESSION['user_name_custom']; ?>" />

Not visible to your users, but the data is passed to your server.

In your server-side code, you'll access the variable like $_REQUEST['extra_label'] .

You have to put the concatenated value into the form field so it will be submitted to the server when you post the form.

$('#userid').blur(function(){
    var value = $('#labletext').text().trim() + ' ' +$(this).val();
    $(this).val(value);
});
<input type="hidden" name="label" value="yourvalue" />

And in your submission you can do this

if(isset($_POST['submit']))
{
 $text = $_POST['text'];
 $label = $_POST['label'];
 $string = $label.$text;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM