开发者

How to make my form sticky when the name field is an array

开发者 https://www.devze.com 2023-03-16 17:22 出处:网络
I\'m a student in my last quarter of school working on a project.I\'m using JQuery to allow the addition of form fields on the fly, so I have to use arrays for the name field so I can collect the info

I'm a student in my last quarter of school working on a project. I'm using JQuery to allow the addition of form fields on the fly, so I have to use arrays for the name field so I can collect the information from potentiall multiple fields that are the same. I'd also like to make said form fields sticky. I've searched Google, searched stackoverflow and asked my veteran developer husband (should have seen the look on his face when I'd stumped him).

I am writing my code like this:

        <input type="text" name="trip_date[]" id="trip_date" value="<?php
        if(isset($_POST['trip_date']))
        {
            echo cleanStickyString($_POST['trip_date']);
        }

What I'm un开发者_如何学Gosure of, is if $_POST[trip_date] needs to actually be $_POST[trip_date[]], though it seems like that would check to see if the array was set.

Any hint in the right direction would be much appreciated! Honesty, I haven't been able to test it yet because my team mates haven't set up the database yet, but because it stumped my husband, I thought I'd get a jump on it and see if anyone out there had any experience they could share. =/

Thank you for your time. I know you all volunteer your time to help others out, it's appreciated!


Not sure what you mean by "sticky", but it seems you are trying to get PHP to render all inputs added with jQuery (and its values) after the form is submitted. Right?

Try this:

foreach($_POST['trip_date'] as $date) {
    echo '<input type="text" name="trip_date[]" value="' . $date . '">';
}


    <input type="text" name="trip_date[]" value="<?php echo "blah";?>
    if(isset($_POST['trip_date']))
    {
        if (sizeof($_POST['trip_date']) > 0) {
            foreach($_POST['trip_date'] AS $trip_date) {
                 echo cleanStickyString($trip_date);
            }
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消