Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 48

Thread: More than one input to a form question - how to process?

  1. #11
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Source Code is this

    Hi Paul
    Gina
    Emma
    John <br />

  2. #12
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Try the other version of the code with the counted loop (in in the edited last post on page 1)
    I just don't get it! lol.

    EDIT: You also might try closing and re-opening your web browser. Sometimes that helps, for some reason. That and refreshing a lot.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #13
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Replaced my script with yours again. Still same output, only this time source code is slightly different.

    Hi Paul
    Martin
    David
    Sarah<br>
    To be expected though!!!

  4. #14
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    ARGH!!! I am getting frustrated for you, lol. Okay, add this before the loop and tell me what it prints.
    Code:
    echo 'There are '.count($names).' names <br>';
    If it says 1, we have a problem with preg_split()
    if it says 4, there is a problem with the loop.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  5. #15
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    lol, I bet I'm more frustrated than you!! But it's nice that you are trying to help so much!!

    ok, I added the line you asked, and it's outputted 1!

  6. #16
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Question, when you are entering the names in the form, are you entering each name on a newline or are you entering them all on one line? If the latter, then the above should work, but if you are entering each name on a newline, you may want to try something like the following:

    Code:
    <?php 
    
    if(isset($_POST['submit'])){ 
    
    $names = preg_split("/[\n\s,]/",$_POST['names']); 
    
     foreach ($names as $thename) {
       echo 'Hi '.$thename.' <br>'; 
     } 
    } 
    else 
    { 
    echo '<form method = "POST" action = "">'; 
    echo '<p>Names</p>'; 
    echo '<p><textarea rows="10" name="names" cols="37"></textarea></p>'; 
    echo '<p><input type="submit" value="Submit" name="submit"></p>'; 
    echo '</form>'; 
    } 
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #17
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    Brilliant thetestingsite! THAT IS IT! I've been using spaces, and you were probably using breaks lol.
    change this
    Code:
    preg_split("/ /",$POST['names']);
    to
    Code:
    preg_split("/\r/",$POST['names']);
    or this
    Code:
    preg_split("/\n/",$POST['names']);
    (depends on your OS)
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  8. #18
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Well what a prat I feel!! For not mentioning that I'm putting each one on a seperate line!!! That kind of fixed things. If I enter all names on 1 line, with a space in between then it outputs it in the right way. Hi name on each line.

    So...
    Input....
    Paul Gina Emma John
    Outputs
    Hi Paul
    Hi Gina
    Hi Emma
    Hi John

    Now, if I do this....
    Paul
    Gina
    Emma
    John
    It does this.....
    Hi Paul
    Hi
    Hi Gina
    Hi
    Hi Emma
    Hi
    Hi John

    lol

  9. #19
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    No, it's not you. I should of figured. lol
    Try this:
    Code:
    if(@preg_match("/\r/",$POST['name'])){
    $names = preg_split("/\r/",$POST['names']);
    }else if(@preg_match("/\n/",$POST['name'])(){
    $names = preg_split("/\n/",$POST['names']);
    }else{
    $names = @preg_split("/ /",$POST['names']);
    }
    should cover all of 'em.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  10. #20
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Ok, played about with it, found this works the best...
    PHP Code:
    $names preg_split("/[\n,]/",$_POST['names']); 
    The \s was adding another "hi" inbetween each line!!

    Thanks to you both for all your help though.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •