Re: Re: Dynamically Created Checkboxes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Steve Staples" <sstaples@xxxxxxxx> wrote in message 
news:1298492194.14826.2425.camel@xxxxxxxxxxx
> On Wed, 2011-02-23 at 14:56 -0500, Gary wrote:
>> "Steve Staples" <sstaples@xxxxxxxx> wrote in message
>> news:1298490417.14826.2418.camel@xxxxxxxxxxx
>> > On Wed, 2011-02-23 at 14:17 -0500, Gary wrote:
>> >> "Jim Lucas" <lists@xxxxxxxxx> wrote in message
>> >> news:4D653673.7040604@xxxxxxxxxxxx
>> >> > On 2/23/2011 4:35 AM, Gary wrote:
>> >> >> "Pete Ford" <pete@xxxxxxxxxxxxx> wrote in message
>> >> >> news:62.C1.32612.D49D46D4@xxxxxxxxxxxxxxx
>> >> >>> This bit?
>> >> >>>
>> >> >>> On 22/02/11 22:06, Gary wrote:
>> >> >>>> for($i=1; $i<=$_POST['counties']; $i++) {
>> >> >>>> if ( isset($_POST["county{$i}"] ) ) {
>> >> >>>
>> >> >>> You loop over $_POST['counties'] and look for $_POST["county$i"]
>> >> >>>
>> >> >>> I suspect that there is no field 'counties' in your form, so the
>> >> >>> server
>> >> >>> is
>> >> >>> complaining about the missing index - seems likely that the
>> >> >>> production
>> >> >>> server
>> >> >>> is not showing the error, but instead just giving up on the page.
>> >> >>>
>> >> >>> I think the IE7/Firefox browser difference is a red herring: it
>> >> >>> wasn't
>> >> >>> actually working in any browser, or the code changed between 
>> >> >>> tests.
>> >> >>> Remember, PHP is server side and generates HTML (or whatever). 
>> >> >>> Unless
>> >> >>> you
>> >> >>> tell the PHP what browser you are using and write PHP code to take
>> >> >>> account
>> >> >>> of that (not generally recommended) then the server output is the
>> >> >>> same
>> >> >>> regardless of browser.
>> >> >>>
>> >> >>> -- 
>> >> >>> Peter Ford, Developer                 phone: 01580 893333 fax: 
>> >> >>> 01580
>> >> >>> 893399
>> >> >>> Justcroft International Ltd.
>> >> >>> www.justcroft.com
>> >> >>> Justcroft House, High Street, Staplehurst, Kent   TN12 0AH 
>> >> >>> United
>> >> >>> Kingdom
>> >> >>> Registered in England and Wales: 2297906
>> >> >>> Registered office: Stag Gates House, 63/64 The Avenue, Southampton
>> >> >>> SO17
>> >> >>> 1XS
>> >> >>
>> >> >>
>> >> >> Pete
>> >> >>
>> >> >> Once again, thank you for your help.
>> >> >>
>> >> >> I was able to get it to work, I did not understand the browser
>> >> >> differences
>> >> >> either, but on my testing server on IE, it worked as I wanted but 
>> >> >> not
>> >> >> on
>> >> >> anything else.  I chopped out most of the code and ended up with 
>> >> >> this:
>> >> >>
>> >> >> if ( isset($_POST['submit']) ) {} else {
>> >> >> print "<form action=\"phpForm3.php\" method=\"POST\">\n";
>> >> >> if ($Recordset1) {
>> >> >> print "<table width=200 border=1>\n";
>> >> >> print "<th>&nbsp; </th>\n";
>> >> >> print "<th> State </th>\n"; //2 fields in Counties table, State and
>> >> >> County
>> >> >> print "<th> County </th>\n";
>> >> >> print "</tr>\n";
>> >> >> //create table
>> >> >> $i = 0;
>> >> >> while ( $row = mysql_fetch_array($Recordset1) ) {
>> >> >> $i++;
>> >> >> print "<tr>\n";
>> >> >> print "<td><input type=\"checkbox\" name=\"county$i\"
>> >> >> value=\"$row[name]\"></td>\n";
>> >> >> echo "<td>{$row['state_id']}</td>\n";
>> >> >> echo "<td>{$row['name']}</td>\n";
>> >> >> echo "</tr>\n";
>> >> >> }//end while
>> >> >> print "</table>\n";
>> >> >> } else {
>> >> >> echo("<P>Error performing query: " .
>> >> >> mysql_error() . "</P>");
>> >> >> }
>> >> >> print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
>> >> >> print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
>> >> >> }
>> >> >> ?>
>> >> >>
>> >> >> Again, thank you.
>> >> >>
>> >> >> Gary
>> >> >>
>> >> >> __________ Information from ESET Smart Security, version of virus
>> >> >> signature database 5899 (20110223) __________
>> >> >>
>> >> >> The message was checked by ESET Smart Security.
>> >> >>
>> >> >> http://www.eset.com
>> >> >>
>> >> >
>> >> > If you would allow me to show you a little easier way of doing this.
>> >> >
>> >> > if ( !isset($_POST['submit']) ) {
>> >> >  echo '<form action="phpForm3.php" method="POST">';
>> >> >  if ($Recordset1) {
>> >> >    echo <<<HEADER
>> >> > <table width=200 border=1>
>> >> >  <tr><th> &nbsp; </th><th> State </th><th> County </th></tr>
>> >> > HEADER;
>> >> >    while ( $row = mysql_fetch_array($Recordset1) ) {
>> >> >      echo <<<ROW
>> >> >  <tr>
>> >> >    <td><input type="checkbox" name="county[]"
>> >> > value="{$row['name']}"></td>
>> >> >    <td>{$row['state_id']}</td>
>> >> >    <td>{$row['name']}</td>
>> >> >  </tr>
>> >> > ROW;
>> >> >  }//end while
>> >> >  echo '</table>';
>> >> > } else {
>> >> >  echo '<p>Error performing query: '.mysql_error().'</p>';
>> >> > }
>> >> >  echo '<input type="submit" name="submit" value="Go" />';
>> >> > }
>> >> >
>> >> > Now, the main thing I want you to see is the line for the country
>> >> > checkbox'es
>> >> >
>> >> > The county[] turns the submitted values into an array.  So, in the
>> >> > processing
>> >> > script, you would do this.
>> >> >
>> >> > <?php
>> >> >
>> >> > ...
>> >> >
>> >> > if ( !empty($_POST['county'])
>> >> >  foreach ( $_POST['county'] AS $id => $name )
>> >> >    echo "{$id} {$name}\n";
>> >> >
>> >> > ...
>> >> > ?>
>> >> >
>> >> > Hope this clears things up for you a little.
>> >> >
>> >> > Enjoy.
>> >> >
>> >> > Jim
>> >>
>> >> In a weird twist, I have/had  the script working, but again it is not
>> >> working in FF or Chrome.  This is a link to the first page which runs 
>> >> you
>> >> through the pages.
>> >>
>> >> I have the submit to trigger upon change so there is no submit button.
>> >> This
>> >> works in IE7.  If I add a submit button, it does not work in any of 
>> >> them.
>> >>
>> >> I am wondering if this is more a problem with the html.
>> >>
>> >>
>> >> http://www.assessmentappeallawyer.com/forum_state.php
>> >>
>> >> This is the code for the first processing page
>> >>
>> >> if ( !isset($_POST['submit']) ) {
>> >>   echo '<form action="forum_delete.php" method="POST">';
>> >>   if ($Recordset1) {
>> >>     echo <<<HEADER
>> >> <table width=200 border=0>
>> >>   <tr><th> &nbsp; </th><th> State </th><th> County </th></tr>
>> >> HEADER;
>> >>     while ( $row = mysql_fetch_array($Recordset1) ) {
>> >>       echo <<<ROW
>> >>   <tr>
>> >>     <td><input type="checkbox" name="county[]"
>> >> value="{$row['name']}"></td>
>> >>     <td>{$row['state_id']}</td>
>> >>     <td>{$row['name']}</td>
>> >>   </tr>
>> >> ROW;
>> >>   }//end while
>> >>   echo '</table>';
>> >> } else {
>> >>   echo '<p>Error performing query: '.mysql_error().'</p>';
>> >> }
>> >>   echo '<input type="submit" name="submit" value="Select" />';
>> >> }
>> >>
>> >> ?>
>> >>
>> >> ****This is the code for the second processing page.
>> >>
>> >>
>> >> <?php
>> >>
>> >>
>> >> if ( !empty($_POST['county']))
>> >>   foreach ( $_POST['county'] AS $id => $name )
>> >>     echo 'You have selected '. " {$name}".'<br />';
>> >>
>> >>
>> >>
>> >> $totalRows_county_result_net= "($totalRows_county_result) + (1)";
>> >>  echo "[$totalRows_county_result_net]";
>> >>  echo "$totalRows_county_result";
>> >>  ?>
>> >> </div>
>> >> <!--eo center-->
>> >>
>> >>
>> >> <?php
>> >> $name=$_POST['name'];
>> >> echo 'You have selected'."$name";
>> >>
>> >> ?>
>> >> <?php
>> >> mysql_free_result($county_result);
>> >> ?>
>> >>
>> >> Again, thank you for any input.
>> >>
>> >> Gary
>> >
>> > I think it may have to do with HTML, or the fact that IE is "helping"
>> > you with your coding... where FF and Chrome are usually more
>> > "literal" (yet better IMO). Also, the fact that "submit" has not been
>> > defined.
>> >
>> > try adding:
>> > <input type="submit" name="submit" value="submit" style="display:
>> > none;" />
>> >
>> > This *SHOULD* give you the submit button, but the style is "hidden" 
>> > now,
>> > so it shouldn't show, but it will fire off the "submit" action... make
>> > sure it is in between the <form></form> tags though.
>> >
>> > Steve
>> >
>> Steve
>>
>> Thank you for your reply, I had inserted a submit button prior, but it 
>> did
>> not work.  I tried your suggestions and got the same result.  I am not
>> seeing anything in the html that should be causing the hick-up, but given
>> the php is run on the server as Peter pointed out, browser issues with 
>> php I
>> have not really encountered before.
>>
>> I can live with a submit button, but living with one that does not 
>> work...
>>
>> Thank you for your input, if you see anything else that seems amiss, 
>> please
>> let me know.
>>
>> Gary
>>
>
> the <form onchange="submit"> as far as I know, isn't a standard/valid
> html attribute...  so I would remove it altogether.
> http://www.w3schools.com/tags/tag_form.asp
>
>
> and try on the <select ... onchange=""> to be
> <select .... onchange="document.forms["Form1"].submit();">
> where Form1 is the id of the form (so add that to the <form...>
> <form id="Form1" ... >
>
> try that... (i haven't been testing... my fault... but I am in the midst
> of work right now to really test it out)
>
> good luck!
>
> Steve

Thank you to everybody that has helped.  As it is now, I have the checkboxes 
appearing in all browers, but I am unable to pass the "checked" values to 
the next page which echo's the choices.

The page that produces the checkboxes is here: (and this works fine)



if ( isset($_POST['submit']) ) { // if form is submitted, process it


print "<form action=\"phpForm3.php\" method=\"POST\">\n";



if ($Recordset1) {
print "<table width=200 border=0>\n";

print "<th>&nbsp; </th>\n";


print "</tr>\n";
//create table
$i = 0;
while ( $row = mysql_fetch_array($Recordset1) ) {
$i++;
print "<tr>\n";

print "<td><input type=\"checkbox\" name=\"county$i\" 
value=\"$row[name]\"></td>\n";

/*echo "<td>{$row['state_id']}</td>\n";*/

echo "<td>{$row['name']}</td>\n";

echo "</tr>\n";

}//end while
print "</table>\n";
} else {
echo("<P>Error performing query: " .
mysql_error() . "</P>");

}
print "<input type=\"hidden\" name=\"counties\" value=\"$i\"/>\n";
print "<input type=\"submit\" name=\"submit\" value=\"Go\"/>\n";
}?>

***************

My query on phpForm3.php is

$query_county_result = "SELECT * FROM counties WHERE name = 'checked' ";

Which is to be displayed by

if ( !empty($_POST['county']))
  foreach ( $_POST['county'] AS $id => $name )
    echo 'You have selected '. " {$name}".'<br />';

I get a blank page and mysql_num_row returns 0

Again, sorry I am not getting this and thank you for all your help.

Gary




__________ Information from ESET Smart Security, version of virus signature database 5904 (20110224) __________

The message was checked by ESET Smart Security.

http://www.eset.com





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux