简体   繁体   中英

<select> and <option> problems in this <form>

i thought i was doing ok:

 <form class="admin_form" id="blog" name="blog" method="post" action="/web/admin.php" >

   <h2>form_blog_section</h2>
   <select name="id_familia" id="id_familia" type="option" value="3">
         <option value ="3">Bicicletas</option>
         <option value ="5">Bike Fiting</option>
         <option value ="6">Rutas cicilstas</option>
         <option value ="7">Tienda</option>
   </select>

    <h2>form_blog_language</h2>
    <select name="id_lan" id="id_lan" type="option" value="2">
          <option value="2"><img src="/img/lan/2.png" />English</option>
          <option value="1"><img src="/img/lan/1.png" />Spanish</option>
    </select>


///// **from here it's not important but i'll still leave it in case**  /////////////
    <h2>form_blog_title</h2><input name="q" id="q" class="q" type="text" value=" "></input>
    <h2>form_blog_text</h2>
    <textarea name="texto" id="texto"  style="max-width:900px;min-width:90%;width:900px;height:400px;padding:2%;" cols="40" >Delete this text and enter here the content as will be thisplayed<br>Please note you can (and should) add styles to your text, images, etc</br></textarea>
    <h2>tags</h2>
    <input name="tags" id="tags" />
    <a href="" class="boton">preview</a>
    <input name="new_blog" id="new_blog" type="submit" value="form_post_blog_button" />
</form>

The problem is when i that i'm getting unexpected values when i recive the input values using PHP $_post:

echo $_POST['id_familia'] => 0 echo $_POST['id_lan'] => 5

And there are not such with this possible values in the form :? And both are 'impossible',

what i'm doing wrong?

I've tried your code and I'm getting

$_POST = Array
(
    [id_familia] => 3
    [id_lan] => 2
    [q] =>  
    [texto] => Delete this text and enter here the content as will be thisplayed<br>Please note you can (and should) add styles to your text, images, etc</br>
    [tags] => 
    [new_blog] => form_post_blog_button
)

So the problem must be somewhere in your PHP code. Aren't you overwriting $_POST somewhere?

Try this php code and tell us what you get:

echo "<pre>".print_r($_POST,1)."</pre>";

Also, the select s should look like this:

<h2>form_blog_section</h2>
<select name="id_familia" id="id_familia">
     <option value="3" selected="selected">Bicicletas</option>
     <option value="5">Bike Fiting</option>
     <option value="6">Rutas cicilstas</option>
     <option value="7">Tienda</option>
</select>

<h2>form_blog_language</h2>
<select name="id_lan" id="id_lan">
      <option value="2" selected="selected"><img src="/img/lan/2.png" />English</option>
      <option value="1"><img src="/img/lan/1.png" />Spanish</option>
</select>

Also, I don't think IMG is allowed in OPTION. But that shouldn't be causing any problems, probably just won't display the image.

i dont like the spaces in the values in the first select..

and i think you dont need close tags for option

you may get 0 if the value is not set at all or if its not an int (int)""==0 (int)"bla"==0

but im not sure :)

also for good coding guidelines i would recommend the parameters be named in english as should be the php code. and try to use full names ("language" not "lan"). if you go back to the code in a couple of years youll be very confused

尝试删除选择标记的类型和值属性。

I'm going to go on a tangent here and ask:

Should the id and name fields for both fields be equal? I may have been drunk in class one morning, but I was under the impression that they shouldn't be the same.

I'd also recommend using CSS when setting styles; it results in much cleaner and maintainable code.

Edit: Nevermind, same id and name for an element is allowed.

Try this. (You shouldn't have the spaces or the .)

Also, you shouldn't have type or value in the select declaration. The name field shouldn't be in form either.

<form class="admin_form" id="blog" method="post" action="/web/admin.php" >

   <h2>form_blog_section</h2>
   <select name="id_familia" id="id_familia">
         <option value="3">Bicicletas
         <option value="5">Bike Fiting
         <option value="6">Rutas cicilstas
         <option value="7">Tienda
   </select>

    <h2>form_blog_language</h2>
    <select name="id_lan" id="id_lan">
          <option value="2"><img src="/img/lan/2.png" />English
          <option value="1"><img src="/img/lan/1.png" />Spanish
    </select>
    <h2>form_blog_title</h2><input name="q" id="q" class="q" type="text" value="" />
    <h2>form_blog_text</h2>
    <textarea name="texto" id="texto"  style="max-width:900px;min-width:90%;width:900px;height:400px;padding:2%;" cols="40" >Delete this text and enter here the content as will be thisplayed<br>Please note you can (and should) add styles to your text, images, etc</br></textarea>
    <h2>tags</h2>
    <input type="text" name="tags" id="tags" />
    <a href="" class="boton">preview</a>
    <input name="new_blog" id="new_blog" type="submit" value="form_post_blog_button" />
</form>

You had a LOT of errors in your code. Try this and see what happens.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM