Is it possible to split an input field into two fields? See details inside.

Discussion in 'PHP' started by qwikad.com, Mar 4, 2012.

  1. #1
    qwikad.com, Mar 4, 2012 IP
  2. HiTEC

    HiTEC Well-Known Member

    Messages:
    92
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    123
    #2
    sure u can make 2 input fields example:
    <input name="area1" type="text" size="20" class="input" maxlength="50" value="<?php echo $area1; ?>">
    <input name="area2" type="text" size="20" class="input" maxlength="50" value="<?php echo $area2; ?>">

    then to be able to save the 1 variable to the database u must join them to the normal sql variable:
    <?php $data['area'] = $area1.'|'.$area2; ?>
    to save to database and u can use the explode php function again if u want to split the $data['area'] to 2 variables:
    <?php $areaz = explode('|',$data['area']); var_dump($areaz); // in var_dump u get the array of the 2 splitted input fields ?>

    Hope this helps.
     
    HiTEC, Mar 4, 2012 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,373
    Likes Received:
    1,720
    Best Answers:
    31
    Trophy Points:
    475
    #3
    It looks easy but I am not sure how it will look in the code. Here's the original code:

    <?php
    }
    else
    {
    ?>


    <input name="area" type="text" size="40" class="input" maxlength="50" value="<?php echo $data['area']; ?>">


    <?php
    }
    ?>

    Will it then look like this?:


    <?php
    }
    else
    {
    ?>


    <input name="area1" type="text" size="20" class="input" maxlength="50" value="<?php echo $area1; ?>">
    <input name="area2" type="text" size="20" class="input" maxlength="50" value="<?php echo $area2; ?>">

    <?php $data['area'] = $area1.'|'.$area2; ?>
    <?php $areaz = explode('|',$data['area']); var_dump($areaz); ?>


    <?php
    }
    ?>

    Does it look right?

    Thank you for the help.
     
    qwikad.com, Mar 4, 2012 IP
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,373
    Likes Received:
    1,720
    Best Answers:
    31
    Trophy Points:
    475
    #4
    Actually, after trying it a few times I don't think it's working. Maybe you can suggest something else?
     
    qwikad.com, Mar 4, 2012 IP