Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable's posting problem

    I can't get the values from Keywords selected to my query after hitting the Save button. I've tried lots of different approaches and can't find where the problem is

    Thanks in advance for any help on this issue.

    Here's the page code where after submitting the form the script should display the KEYWORDS entered to the left select list.

    PHP Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function move(fbox, tbox) {
         var arrFbox = new Array();
         var arrTbox = new Array();
         var arrLookup = new Array();
         var i;
         for(i=0; i<tbox.options.length; i++) {
              arrLookup[tbox.options[i].text] = tbox.options[i].value;
              arrTbox[i] = tbox.options[i].text;
         }
         var fLength = 0;
         var tLength = arrTbox.length
         for(i=0; i<fbox.options.length; i++) {
              arrLookup[fbox.options[i].text] = fbox.options[i].value;
              if(fbox.options[i].selected && fbox.options[i].value != "") {
                   arrTbox[tLength] = fbox.options[i].text;
                   tLength++;
              } else {
                   arrFbox[fLength] = fbox.options[i].text;
                   fLength++;
              }
         }
         arrFbox.sort();
         arrTbox.sort();
         fbox.length = 0;
         tbox.length = 0;
         var c;
         for(c=0; c<arrFbox.length; c++) {
              var no = new Option();
              no.value = arrLookup[arrFbox[c]];
              no.text = arrFbox[c];
              fbox[c] = no;
         }
         for(c=0; c<arrTbox.length; c++) {
             var no = new Option();
             no.value = arrLookup[arrTbox[c]];
             no.text = arrTbox[c];
             tbox[c] = no;
         }
    }

    function selectAll(box) {
         for(var i=0; i<box.length; i++) {
         box[i].selected = true;
         }
    }
    </script>
    </head>
    <body>
    <p>
      <?
      
    if($save=Save){
          echo 
    $keywords;
      }
      
    ?>
    </p>
    <form method="post" action="photoedit.php?save=Save" name="editphoto" enctype="multipart/form-data">
      <table border="0" cellpadding="2" cellspacing="1" id="sqlcontainer" name="sqlcontainer">
        <tr>
          <td  align="center" bgcolor="#dbe7f9">photo_title_en</td>
          <td align="center" bgcolor="#dbe7f9" nowrap="nowrap"> varchar(255) </td>
          <td bgcolor="#dbe7f9"><input type="text" name="photo_title_en" value="" size="40" maxlength="255">
          </td>
          <td bgcolor="#dbe7f9">&nbsp; </td>
          <td bgcolor="#dbe7f9">&nbsp; </td>
        </tr>
        <tr>
          <td  align="center" bgcolor="#e6f0ff">photo_keywords</td>
          <td align="center" bgcolor="#e6f0ff" nowrap="nowrap">text</td>
          <td align="right" bgcolor="#e6f0ff"><select multiple size="10" name="keywords[]" id="keywords" style="width:150" onDblClick="move(this.form.keywords,this.form.keyword_pad)">
            </select>
          </td>
          <td bgcolor="#e6f0ff"><input type="button" onClick="move(this.form.keywords,this.form.keyword_pad)" value=">>" id=button1 name=button1>
            <input type="button" onClick="move(this.form.keyword_pad,this.form.keywords)" value="<<" id=button2 name=button2>
          </td>
          <td bgcolor="#e6f0ff"><select name="keyword_pad" id="keyword_pad" size="10" multiple="multiple" onDblClick="move(this.form.keyword_pad,this.form.keywords)">
              <option value="Couple, ">Couple</option>
              <option value="Child, ">Child</option>
              <option value="Man, ">Man</option>
              <option value="Two, ">Two</option>
              <option value="Female, ">Female</option>
              <option value="Young, ">Young</option>
            </select>
          </td>
        </tr>
      </table>
      <br >
      <input name="submit" type="submit" tabindex="119" value="Save">
    </form>
    </body>
    </script>
    </html>

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    as far as I can tell, you're passing $keywords as an array but you're trying to output it as a variable.
    try
    PHP Code:
    foreach($keywords as $keyword){
    echo 
    $keyword;


  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Nancy,

    Even though it still doesn't work. The Keywords aren't getting up there after submit.

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    have you set $keywords anywhere? eg. $keywords = $_POST['keywords'] ... or $_POST['keywords[]'] cant remember the exact syntax.

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Yes, $keywords[] is set in the form (red)
    Code:
    <form method="post" action="photoedit.php?save=Save" name="editphoto" enctype="multipart/form-data"> 
      <table border="0" cellpadding="2" cellspacing="1" id="sqlcontainer" name="sqlcontainer"> 
        <tr> 
          <td  align="center" bgcolor="#dbe7f9">photo_title_en</td> 
          <td align="center" bgcolor="#dbe7f9" nowrap="nowrap"> varchar(255) </td> 
          <td bgcolor="#dbe7f9"><input type="text" name="photo_title_en" value="" size="40" maxlength="255"> 
          </td> 
          <td bgcolor="#dbe7f9">&nbsp; </td> 
          <td bgcolor="#dbe7f9">&nbsp; </td> 
        </tr> 
        <tr> 
          <td  align="center" bgcolor="#e6f0ff">photo_keywords</td> 
          <td align="center" bgcolor="#e6f0ff" nowrap="nowrap">text</td> 
          <td align="right" bgcolor="#e6f0ff"><select multiple size="10" name="keywords[]"  id="keywords" style="width:150" onDblClick="move(this.form.keywords,this.form.keyword_pad)"> 
            </select> 
          </td> 
          <td bgcolor="#e6f0ff"><input type="button" onClick="move(this.form.keywords,this.form.keyword_pad)" value=">>" id=button1 name=button1> 
            <input type="button" onClick="move(this.form.keyword_pad,this.form.keywords)" value="<<" id=button2 name=button2> 
          </td> 
          <td bgcolor="#e6f0ff"><select name="keyword_pad" id="keyword_pad" size="10" multiple="multiple" onDblClick="move(this.form.keyword_pad,this.form.keywords)"> 
              <option value="Couple, ">Couple</option> 
              <option value="Child, ">Child</option> 
              <option value="Man, ">Man</option> 
              <option value="Two, ">Two</option> 
              <option value="Female, ">Female</option> 
              <option value="Young, ">Young</option> 
            </select> 
          </td> 
        </tr> 
      </table> 
      <br > 
      <input name="submit" type="submit" tabindex="119" value="Save"> 
    </form>

  • #6
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    the form field keywords[] != $keywords

  • #7
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Nancy,

    Yes, but even if I change it to $keywords the variable isn't posted, seems like the form field keywords doesn't exist. I think that this has something to do with the Javascript and not the PHP of HTML.

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    PHP Code:
     print_r($_POST); 
    should show what is in post

  • #9
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    doh! ofcourse...
    Had to actually compile see this in action to realise what the problem is, your keywords arent being posted because they're not selected
    add a little javascript into your on_submit that selects everything in keywords.

    Code:
    <form .... onsumbit="selectAllOptions(this.keywords)">
    Code:
    function selectAllOptions(obj){
    	
    	for(var i=0;i<obj.options.length;i++)
    	     {
    	         obj.options[i].selected = true;
    	     }
    		return true;
    }

  • #10
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nancy,

    As you may have noticed, I have two select lists: the left one is for the "keywords" that I want to be saved, and the right one is the "keyword_pad" that is populated from the database.

    What's happening now after your print_r post? Well, I noticed that the only variables passed to the script will come from the "keyword_pad" select IF and ONLY those which are in fact selected.

    Now, the problem is how to get the left select to pass the variables into the the $_POST. Humm... it seems this is more Javascript.

  • #11
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    in select boxes only the selected items are passed through with the form data.

    ...I'm guessing you havent seen my previous post

  • #12
    New Coder
    Join Date
    Jul 2002
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right. Now I have the variable out there thanks to you Nancy

    Now I'll try to find a way to "auto-select" the items on the left select box, like an onChange...

    Thnks again for your valuable help!

  • #13
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    Quote Originally Posted by NancyJ
    Code:
    <form .... onsumbit="selectAllOptions(this.keywords)">
    Code:
    function selectAllOptions(obj){
    	
    	for(var i=0;i<obj.options.length;i++)
    	     {
    	         obj.options[i].selected = true;
    	     }
    		return true;
    }
    should select all options in keywords onsubmit


  •  

    Posting Permissions

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