1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to capture submitted data into arrary...

Discussion in 'PHP' started by strgraphics, Jun 29, 2011.

  1. #1
    Hello mates,
    is there any way to capture the form data into the string array..,

    in html:

    <select id="dropdown" style="border: 1px solid #005e9d;">
    <option selected>--- Please Select ---</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    </select>



    in php;


    $fn1=$_POST['fn1'];
    $ln1=$_POST['ln1'];

    $fn2=$_POST['fn2'];
    $ln2=$_POST['ln2'];

    $fn3=$_POST['fn3'];
    $ln3=$_POST['ln3'];

    $fn4=$_POST['fn4'];
    $ln4=$_POST['ln4'];

    $fn5=$_POST['fn5'];
    $ln5=$_POST['ln5'];

    $fn6=$_POST['fn6'];
    $ln6=$_POST['ln6'];

    $fn7=$_POST['fn7'];
    $ln7=$_POST['ln7'];

    $fn8=$_POST['fn8'];
    $ln8=$_POST['ln8'];


    is there any way to write any for loop and take into array...????

    Thanks in advance....!!!!!!!
     
    strgraphics, Jun 29, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    If you add the name attribute to the select tag you can access it on the posted page.

    <select id="dropdown" name="select_this" style="border: 1px solid #005e9d;">
    <option selected>--- Please Select ---</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    </select>

    $value = $_POST['select_this'];
     
    jestep, Jun 29, 2011 IP
  3. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hi jestep, thanks for your reply...
    but actually am generating first name(fn), last name(ln) dynamically with javascript., if i select 4, then 4 times firstname, lastname will be displayed, so when i fill the details -- > on submit in my php how can i take take all of them into an array unlike writing....


    $fn1=$_POST['fn1'];
    $ln1=$_POST['ln1'];

    $fn2=$_POST['fn2'];
    $ln2=$_POST['ln2'];

    $fn3=$_POST['fn3'];
    $ln3=$_POST['ln3'];

    $fn4=$_POST['fn4'];
    $ln4=$_POST['ln4'];

    some thing like...

    for($i=1;$i<=4;$i++)
    {

    $fn[$i]=$_POST['fn'][$i];
    $ln[$i]=$_POST['ln'][$i];
    }

    its now working for me.., hope you got me....thanks a lottt
     
    strgraphics, Jun 29, 2011 IP
  4. balaganesh

    balaganesh Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <select id="dropdown" name="select_this" style="border: 1px solid #005e9d;">
    <option selected>--- Please Select ---</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    </select>

    $value = $_POST['select_this'];
     
    balaganesh, Jun 29, 2011 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    Try this

    
    for($i=1;$i<=4;$i++)
    {
    
    $fnvar_text = 'fn'.$i;
    $lnvar_text = 'ln'.$i;
    
    $$fnvar_text = $_POST['fn'.$i];
    $$lnvar_text = $_POST['ln'.$i];
    }
    
    PHP:
    then access the variables using $fn1 , $fn2 or $ln1 , $ln2 , ...etc
     
    ads2help, Jun 30, 2011 IP
  6. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Hello ads2help, its worked thank you so much........
    But little issue while am sending the mail..., actually i used your for loop concept while sending the mail.., but its not working...

    
    $to="strkgroups@gmail.com";
    			$psubject="Registration Information";
    			$headers = "str\r\n";
    			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    			//$subject=$psubject;
    			$body="
    						<table width=500px style='border:1px solid #425f9c;background: #f7f8fb'>						
    						<tr>
    						<td style='padding:10px;border-top:1px solid #565e70'>			
    						 First Name: <b>$fn</b><br>
    						 Last Name: <b>$ln</b><br>
    						 Group Name: <b>$gn</b><br><br>
    						 No. of persons in group: <b>$sel</b><br><br><br>
                                   
                  
    							  for($i=1;$i<=$sel;$i++)
    							 {
    									$fnvar_text = 'fn'.$i;
    									$lnvar_text = 'ln'.$i;
    
    									First Name: <b>$fnvar_text</b><br>
    						            Last Name: <b>$fnvar_text</b><br><br>
    
    							 }
    
    
                              Group Lead email address :  <b>$glea</b><br>
                              Group lead phone number :  <b>$glpn</b><br>
                   
    						  </td></tr></table>";
    						
    			//$reslt = mail($to, $psubject, $body,$headers);
    
    			if(mail($to, $psubject, $body,$headers))
    			{
    			echo "<center><font COLOR='#678125' size='2' face='verdana'><b>Message has been sent Successfully..!!";
    			}
    			else
    				{
    			echo "<font color='#f52e41'><center>Failed to send the message....!</font></center>";
    				}
    
    PHP:
    can you help me to fix this please........, thank a lottttttttt
     
    strgraphics, Jun 30, 2011 IP
  7. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    And friend i tested with this ...
    
     $to="sivateja.kandula@gmail.com";
    			$psubject="Registration Information_talentforeducation.com";
    			$headers = "From: TalentForEducation.com\r\n";
    			$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    			//$subject=$psubject;
    			$body .="
    						<table width=500px style='border:1px solid #425f9c;background: #f7f8fb'>						
    						<tr>
    						<td style='padding:10px;border-top:1px solid #565e70'>			
    						 First Name: <b>$fn</b><br>
    						 Last Name: <b>$ln</b><br>
    						 Group Name: <b>$gn</b><br><br>
    						 No. of persons in group: <b>$sel</b><br><br><br>
                    ";  
    				?>
    
                           <?php
    							  for($i=1;$i<=$sel;$i++)
    							 {
    									
                                     $body .="
    									First Name: <b>$fn.$i</b><br>
    						            Last Name: <b>$fn.$i</b><br><br>";
    
    							 }
                            ?>
                      
    
    				  <?php
                     $body .="         Group Lead email address :  <b>$glea</b><br>
                              Group lead phone number :  <b>$glpn</b><br>
                   
    						  </td></tr></table>";
    						
    			//$reslt = mail($to, $psubject, $body,$headers);
    
    			if(mail($to, $psubject, $body,$headers))
    			{
    			echo "<center><font COLOR='#678125' size='2' face='verdana'><b>Message has been sent Successfully..!!";
    			}
    			else
    				{
    			echo "<font color='#f52e41'><center>Failed to send the message....!</font></center>";
    				}
    
    PHP:
    But not getting the required output
     
    Last edited: Jun 30, 2011
    strgraphics, Jun 30, 2011 IP
  8. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Yes its working...

    Thanks friend, thanks so much..
     
    strgraphics, Jun 30, 2011 IP