Foros del Web » Programando para Internet » PHP »

Ayuda con datos Lista desplegable.

Estas en el tema de Ayuda con datos Lista desplegable. en el foro de PHP en Foros del Web. Hola gente haber si pueden echarme un cable con esto. Tengo dos archivos php, uno es el "form.php" donde tengo un formulario de envió con ...
  #1 (permalink)  
Antiguo 11/11/2009, 02:54
Avatar de xiscomax  
Fecha de Ingreso: febrero-2006
Mensajes: 379
Antigüedad: 18 años, 2 meses
Puntos: 5
Pregunta Ayuda con datos Lista desplegable.

Hola gente haber si pueden echarme un cable con esto.

Tengo dos archivos php, uno es el "form.php" donde tengo un formulario de envió con un campo desplegable (location) con 4 opciones a elegir.

Este funciona bien.

El otro archivo es el edit.php donde el usuario puede editar su anuncio, en este aparecen todos los campos del formulario anterior incluido el campo desplegable (location) con los datos que añadió.

El problema es que si realiza o no cambios y le da al botón de guardar, el formulario de edit.php detecta el campo (location) como vació, teniendo en cuenta que este campo le muestra una de las 4 opciones que eligio.

el campo location de edit.php es este.

Código PHP:
    <p><label><b>Location </b> *(Options)<br />
    <select name='location' id='location' class='postform' >
    <option value="<?php if ($hfield == '3') { echo $errcolor; } ?>" ><?php echo get_post_meta($getmyad->ID"location"true); ?> </option>
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
    <option value="Option 4">Option 4</option>
    </select></label></p>

y el codigo entero de edit.php es este.

Código PHP:
<?php
/*
Name: Edit Ad Page
*/


$wpdb->hide_errors(); 
auth_redirect_login(); // if not logged in, redirect to login page
nocache_headers();

global 
$userdata;
get_currentuserinfo(); // grabs the user info and puts into vars


// check to see if the form has been posted. If so, validate the fields
if(!empty($_POST['submit']))
{
   
   
$title        trim($_POST['post_title']);
   
$price         cp_filter($_POST['price']);
   
$location     cp_filter($_POST['location']);
   
$phone         cp_filter($_POST['phone']);
   
$email         cp_filter($_POST['email']);
   
$name_owner     cp_filter($_POST['name_owner']);
   
$cp_adURL    cp_filter($_POST['cp_adURL']);   
   
   
$description    trim($_POST['description']);
   
    if(
$title == '')
    {
      
$errmsg __('Ad title cannot be blank','cp');
      
$hfield '1';
    }
    else if(
$price == '')
    {
      
$errmsg __('Price cannot be blank','cp');
      
$hfield '2';
    }
    else if(
$location == '')
    {
      
$errmsg __('Location cannot be blank','cp');
      
$hfield '3';
    }
    else if(
$email == '')
    {
      
$errmsg __('Email address cannot be blank','cp');
      
$hfield '5';
    }
    else if ( !
cp_check_email($email) ) {
      
$errmsg __('Email address is not valid','cp');
      
$hfield '5';
    }
    else if(
$name_owner == '')
    {
      
$errmsg __('Name cannot be blank','cp');
      
$hfield '6';
    }
    else if(
$description == '')
    {
      
$errmsg __('The description cannot be blank','cp');
      
$hfield '7';
    }

    

// if there are no errors, then process the ad updates
if($errmsg == '')
    {
        if ( 
get_option('filter_html') != "yes" ) {
            
$description     cp_filter($description);
        }

          
      
// Put all post variables into an array 
      
$my_ad = array();
      
$my_ad['ID'] = trim($_POST['ad_id']);
      
$my_ad['post_title'] = cp_filter($_POST['post_title']);
      
$my_ad['post_content'] = $description;

          
//Add or edit images
          // First delete any images as posted
          
$image_folder_name "folder-images";
          
$upload_arr wp_upload_dir(); 
      
$imagedirectory trailingslashit($upload_arr['basedir']) . $image_folder_name;
      
$delimages=$_POST['delimages'];
      
$noofdel=0;
          
$notdel=0;
    
$postedimages explode(","get_post_meta($my_ad['ID'], 'images'true));
    
$totalimages=count($postedimages);
        if (!empty(
$delimages)){
        foreach (
$delimages as $imagekey=> $delimage){ 
            if (
$delimage!=""){
                                
$imagetodelete $imagedirectory.'/'.basename($postedimages[$delimage]);                                
                    
$delstatus=unlink($imagetodelete);
                           if(
$delstatus=="1"){
                            
$noofdel++;                            
    
//                        $listofdeleted=$delmessages.basename($postedimages[$delimage])." was deleted successfully.<br/>"; // can be used to see files being deleted
                            
array_splice($postedimages,$delimage,1);    
                           } else { 
                            
$notdel++;
       
//                        $listofnotdeleted=$delmessages.basename($postedimages[$delimage])." was not deleted<br/>";  // can be used to see files being deleted
                           
}     
                      
                    }
        }
        
$delmessages=$noofdel." images were deleted successfully<br/>".$listofdeleted;
        if(
$notdel!=0){
        
$delmessages.=$notdel."images were not deleted<br/>".$listofnotdeleted;
    }  
    }
        

        
// Second Insert new images
    //1024 bytes = 1kb
    //1024000 bytes = 1mb
    //  $image_folder_name = "folder-images";
    
$size_bytes 1024000;
    
$size_mb $size_bytes 1024000;
    
$limitedext = array(".gif",".png",".jpg",".jpeg");

        
// http://codex.wordpress.org/Function_Reference/wp_upload_dir
//        $upload_arr = wp_upload_dir();

//        $dir_to_make = trailingslashit($upload_arr['basedir']) . $image_folder_name;
        // $dir_to_make = "wp-content/uploads/folder-images";
        
$image_baseurl trailingslashit($upload_arr['baseurl']) . $image_folder_name;
        
$image_name substr(sanitize_title(alphanumericAndSpace($title)), 020);
        
        
$i rand();
        
$newimages "";
        
$err2 "";
        while(list(
$key,$value) = each($_FILES['images']['name'])) {
            if(!empty(
$value)) {
                
$filename strtolower($value);
                
$filename str_replace(" ""-"$filename);
                
//get image extension
                
$tipul strrchr($filename,'.');
                
$filename $image_name."-$i".$tipul;
                
$add "$imagedirectory/$filename";
                
$image "$image_baseurl/$filename";
                
//$add = "$filename";

           //Make sure that file size is correct
                
$file_size $_FILES['images']['size'][$key]; //getting the right size that coresponds with the image uploaded
                   
if ($file_size == "0"){
                      
$err2 .= __('The file $value has 0 bytes.','cp') . "<br />";
                   } else {
                    if (
$file_size $size_bytes){
                          
$err2 .= __('The file $value is bigger than 2MB.','cp') . "<br />";
                       }
                   }
                   
//check file extension
                   
$ext strrchr($filename,'.');
                   if ( (!
in_array(strtolower($ext),$limitedext)) ) {
                      
$err2 .= __('The file $value is not an image.','cp') . "<br />";
                   }


                
//echo $_FILES['images']['type'][$key];
                
if ( $err2 == "" ) {
                    if (!
file_exists($imagedirectory)) { mkdir($imagedirectory0777); }
                    
copy($_FILES['images']['tmp_name'][$key], $add);
                    
chmod("$add",0777);

                    
//$images .= get_option('home')."/".$add.",";
                    
$newimages .= $image ",";

                }
                
$err2 "";
                
$i++;
            }
//if empty $value
        
}//end while

        // Create new images array
    
array_merge($postedimages);
    foreach (
$postedimages as $image){
        if (
$image!=""){    
            
$images=$images.$image.',';
        }
    }
        



      
// Update the ad in the db
      
wp_update_post$my_ad );

      
// now go back and update the meta fields
      
update_post_meta($_POST['ad_id'], 'price'$price);
      
update_post_meta($_POST['ad_id'], 'location'$location);
      
update_post_meta($_POST['ad_id'], 'phone'$phone);
      
update_post_meta($_POST['ad_id'], 'email'$email);
      
update_post_meta($_POST['ad_id'], 'name'$name_owner);
      
update_post_meta($_POST['ad_id'], 'cp_adURL'$cp_adURL);
      
update_post_meta($_POST['ad_id'], 'images',$images.$newimages); 
      
      
$cp_dashboard_url $_POST['dashboard_url'];
      
      
$errmsg '<div class="box-yellow"><b>' .$delmessages__('Your ad has been updated!','cp') . '</b><br /><br /> <a href=".' $cp_dashboard_url '">' __('My Dashboard &rsaquo;&rsaquo;','cp') . '</a></div>'
    
    } else {
    
      
$errmsg '<div class="box-red"><strong>**  ' $errmsg ' **</strong></div>'
      
$errcolor 'style="background-color:#FFEBE8;border:1px solid #CC0000;"';
    }

  
}      
      

// get the ad id from the querystring. Need this for the sql statement
$aid $_GET["aid"];

$querystr "SELECT wposts.* FROM $wpdb->posts wposts WHERE ID = $aid AND post_status <> 'draft' AND post_author = $userdata->ID";

// pull ad fields from db
$getmyad $wpdb->get_row($querystrOBJECT);




// start main edit page
require_once dirname__FILE__ ) . '/form_process.php';

get_header(); 
include_classified_form();
?>

<style type="text/css">
.mid2 { border:1px solid #CCC; margin-bottom:10px; padding:5px; }
</style>

<script type="text/javascript">
function textCounter(field,cntfield,maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else cntfield.value = maxlimit - field.value.length; }
</script>

<div class="content">
        <div class="main ins">
        
            <div class="left">
                
                <div class="product">
Continua en el siguiente post ....
  #2 (permalink)  
Antiguo 11/11/2009, 02:55
Avatar de xiscomax  
Fecha de Ingreso: febrero-2006
Mensajes: 379
Antigüedad: 18 años, 2 meses
Puntos: 5
Pregunta Respuesta: Ayuda con datos Lista desplegable.

Continua aqui....

Código PHP:
<?php 
if (get_option('cp_ad_edit') != "no") { 
?>
                
    <?php if ($getmyad): ?>


    <?php echo $err2.$errmsg?>    

    <form name="edit_ad" id="edit_ad" action="" method="post" enctype="multipart/form-data">
    <input type="hidden" name="ad_id" value="<?php echo $getmyad->ID?>" />
    <input type="hidden" name="dashboard_url" value="<?php echo cp_dashboard_url?>" />


    <h2><?php _e('Edit Your Ad','cp');?></h2>
       <p><?$delmessages?><p>
    <p><?php _e('Edit the fields below and click save to update your ad. Your changes will be updated instantly on the site.','cp');?></p>

    <p><strong><?php _e('Ad ID:','cp');?></strong> <span style="background-color:#eee;padding:5px;"><?php echo $getmyad->ID?></span></p>


    <p><label><b><?php _e('Title','cp');?></b> *<br />
    <input <?php if ($hfield == '1') { echo $errcolor; } ?> type="text" name="post_title" class="mid2" id="post_title" value="<?php echo $getmyad->post_title?>" size="50" maxlength="100" /></label></p>

    <p><label><b><?php _e('Price','cp');?></b> *<br />
    <input <?php if ($hfield == '2') { echo $errcolor; } ?> type="text" name="price" class="mid2" id="price" value="<?php echo get_post_meta($getmyad->ID"price"true); ?>" size="50" maxlength="100" /></label></p>
    
    <p><label><b><?php _e('Location','cp');?></b> *<br />
    <input <?php if ($hfield == '3') { echo $errcolor; } ?> type="text" name="location" class="mid2" id="location" value="<?php echo get_post_meta($getmyad->ID"location"true); ?>" size="50" maxlength="100" /></label></p>

    <p><label><b>Location </b> *(Options)<br />
    <select name='location' id='location' class='postform' >
    <option value="<?php if ($hfield == '3') { echo $errcolor; } ?>" ><?php echo get_post_meta($getmyad->ID"location"true); ?> </option>
    <option value="Option 1">Option 1</option>
    <option value="Option 2">Option 2</option>
    <option value="Option 3">Option 3</option>
    <option value="Option 4">Option 4</option>
    </select></label></p>
        
    <p><label><b><?php _e('Name','cp');?></b> *<br />
    <input <?php if ($hfield == '6') { echo $errcolor; } ?> type="text" name="name_owner" class="mid2" id="name_owner" value="<?php echo get_post_meta($getmyad->ID"name"true); ?>" size="50" maxlength="100" /></label></p>

    <p><label><b><?php _e('Email','cp');?></b> *<br />
    <input <?php if ($hfield == '5') { echo $errcolor; } ?> type="text" name="email" class="mid2" id="email" value="<?php echo get_post_meta($getmyad->ID"email"true); ?>" size="50" maxlength="100" /></label></p>
    
    <p><label><b><?php _e('Phone','cp');?></b><br />
    <input type="text" name="phone" class="mid2" id="phone" value="<?php echo get_post_meta($getmyad->ID"phone"true); ?>" size="50" maxlength="100" /></label></p>
    
    <p><label><b><?php _e('URL','cp');?></b><br />
    <input type="text" name="cp_adURL" class="mid2" id="cp_adURL" value="<?php echo get_post_meta($getmyad->ID"cp_adURL"true); ?>" size="50" maxlength="250" /></label></p>

    

    <p><b><?php _e('Description','cp');?></b> *<br />
    <textarea <?php if ($hfield == '7') { echo $errcolor; } ?> name="description" class="mid2" id="description" rows="15" cols="57" onkeydown="textCounter(document.edit_ad.description,document.edit_ad.remLen1,5000)"
                    onkeyup="textCounter(document.edit_ad.description,document.edit_ad.remLen1,5000)"><?php echo stripslashes($getmyad->post_content); ?></textarea></p>

    <div class="limit">
        <input readonly="readonly" type="text" name="remLen1" size="4" maxlength="4" value="5000" style="width: 50px;" /><span style="font-size:11px;"> <?php _e('characters left','cp'); ?></span>
    </div>


    <p><b><?php _e('Images to be deleted','cp');?><small>(<?php _e('check images to be deleted','cp'); ?>)</small></b><br />
        
    <? 
    $matches 
explode(","get_post_meta($getmyad->ID'images'true));    
    foreach(
$matches as $key=>$var) {
        if (
$var != "") {
            
$thumb_var str_replace(get_option('home')."/wp-content/uploads/folder-images/"""$var);
            
$single_thumb_img_url get_bloginfo('template_url')."/includes/img_resize.php?width=100&amp;height=100&amp;url=".$thumb_var;
            echo 
"<input type=\"checkbox\" name=\"delimages[]\" value=\"$key\"><img src=\"$single_thumb_img_url\"/>";
            
//echo "<a href=\"$var\" rel=\"group\"><img src=\"$single_thumb_img_url\" class=\"size-thumbnail\" alt=\"".get_the_title()."\" title=\"".get_the_title()."\" /></a>"."\n";
        
} else {
            if ( 
$matches[0] == "") {
                
_e('There are no images','cp');
            }
        }
    }


    
?><small>(<?php _e('check images to be deleted','cp'); ?>)</small>

    <p><b><?php _e('Add images','cp'); ?> <small>(<?php _e('images must be under 1 MB','cp'); ?>)</small></b>
                <input type="file" name="images[]" class="wwIconified" value="<?php echo $_POST['images']; ?>"/><br /><p>


    <p class="submit"><input type="submit" class="lbutton" value="<?php _e('Update Ad &raquo;','cp'?>" name="submit" /></p>
    </form>


  
  <?php else : ?>

    <h2 class="center"><?php _e('Ad Not Found','cp');?></h2>
    <p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.','cp');?><br /> <?php _e('Go to','cp');?> <a href="<?php bloginfo('url')?><?php echo cp_dashboard_url?>"><?php _e('My Dashboard','cp');?> &rsaquo;&rsaquo;</a></p>

<?php endif; ?>

<?php } else { ?>

<h2 class="center"><?php _e('Ad Editing is Disabled','cp');?></h2>
    <p class="center"><?php _e('Your site administrator has disabled ad editing. Please contact them for further instructions.','cp');?><br /> <?php _e('Go to','cp');?> <a href="<?php bloginfo('url')?><?php echo cp_dashboard_url?>"><?php _e('My Dashboard','cp');?> &rsaquo;&rsaquo;</a></p>

<?php ?>



                </div>
            </div>
    
            <div class="right">
            
            <?php if (function_exists('dynamic_sidebar')&&dynamic_sidebar('Page Sidebar')):else: ?>
                
                <li><h2><?php _e('Archives','cp'); ?></h2>
                    <ul>
                    <?php wp_get_archives('type=monthly'); ?>
                    </ul>
                </li>

                <?php wp_list_categories('show_count=1&title_li=<h2>'.__('Categories','cp').'</h2>'); ?>
                
            <?php endif; ?>
            
            </div>
            <div class="clear"></div>
        </div>
    </div>

<?php get_footer(); ?>
Agradecería mucho si alguien pudiera echarme un cable.
Saludos y gracias desde ya..
  #3 (permalink)  
Antiguo 11/11/2009, 10:40
Avatar de xiscomax  
Fecha de Ingreso: febrero-2006
Mensajes: 379
Antigüedad: 18 años, 2 meses
Puntos: 5
Respuesta: Ayuda con datos Lista desplegable.

Alguien que pueda ayudarme porfa... al igual no explico bien mi problema........ ¿¬¬
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:52.