Ver Mensaje Individual
  #5 (permalink)  
Antiguo 07/05/2009, 14:14
bellleti
 
Fecha de Ingreso: abril-2008
Mensajes: 144
Antigüedad: 16 años, 8 meses
Puntos: 1
De acuerdo Respuesta: ayuda cositas en zendframework

buenas gatorV, pues esta funcion la encontre en una pagina que tengo que actualizar, creo que lo utiliza para recuperar las variables del formulario de contacto:

te paso el controlador i el phtml. i me das tu opinion

Código PHP:
public function indexAction() {
            
$this->_redirect("contact/eticket_new");
        }

        public function 
eticketnewAction() {
            
Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
            
$view $this->view;

            
$ticket = array();
            
$vars = array('category_id''question''name''email');
            foreach (
$vars as $var) {
                
$ticket[$var] = var_from_post($var);
            }
            
$ticket['subcategory_id'] = var_from_post('subcategory_id_' $ticket['category_id']);

            if (!
is_numeric($ticket['category_id'])) {
                
$this->first_time_show($view);
                return;
            }

            
// if not first time, check values for correctness
            
$messages = array();
            if (!
is_numeric($ticket['category_id']) || $ticket['category_id'] < 1) {
                
$messages[] = "Please choose a category";
            }

            if (!
is_numeric($ticket['subcategory_id']) || $ticket['subcategory_id'] < 1) {
                
$messages[] = "Please choose a subcategory";
            }

            if (empty(
$ticket['question'])) {
                
$messages[] = "Please write a question";
            }

            if (empty(
$ticket['name'])) {
                
$messages[] = "Please write your name";
            }

            if (empty(
$ticket['email'])) {
                
$messages[] = "Please write your email";
            }

            
$seccode var_from_post("seccode");
            if (empty(
$seccode)) {
                
$messages[] = "Please write the spam control text";
            } else {
                
$seccode_real var_from_session('captcha_neweticket');
                unset(
$_SESSION['captcha_neweticket']);
                if (
strtoupper($seccode) != strtoupper($seccode_real)) {
                    
$messages[] = "The spam control text was not correct";
                }
            }

            
// if errors reshow form
            
if (!empty($messages)) {
                
$this->any_time_show($view$ticket$messages);
                return;
            } else {
                
// save
                
try {
                    
$ticket['code'] = "SUPPORT" $this->eticket_code_unique();
                    
$this->save_new_ticket($ticket);

                    
// send mail
                    
$this->eticket_new_sendmail($ticket);

                    
// redirect to OK page
                    
header("Location: " "/contact/eticket_new_thanks?code=" $ticket['code']);
                    die();
                } catch (
Exception $e) {
                    
error_log("Saving new ticket: " $e->getMessage());

                    
$messages[] = "Problem saving ticket, please try again in a few minutes";
                    
$this->any_time_show($view$ticket$messages);
                }
            }
        } 
phtml.
Código PHP:
<?php
    
if (isset($this->messages)) {
        foreach(
$this->messages as $message) {
?>
<span style="color: red; font-weight: bold;"><?=$this->translate($message)?></span>
<br/>
<?php    ?>
<br/>
<?php
    
}
?>

<style>
#neweticket th {
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}
</style>    

<form method=post action="?">

<table id="neweticket">
  <tr>
    <th><?=$this->translate("Category:")?></th>
    <td>
<select id="category_id" name="category_id">
    <option value="0"> --- </option>
    <?php foreach ($this->categories as $item) { ?>
    <option value="<?=$item['id']?>"
        <?php if ($item['id'] == $this->category_id) { ?> selected="selected" <?php ?>
        ><?=$item['title']?></option>
    <?php }?>
</select>
    </td>
  </tr>
  <tr>
    <th><?=$this->translate("Subcategory:")?></th>
    <td>
<select id="subcategory_id_0" name="subcategory_id_0" style="display: none;">
    <option value="0">  --- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
</select>
<?php foreach ($this->categories as $item) { ?>
<select id="subcategory_id_<?=$item['id']?>" name="subcategory_id_<?=$item['id']?>" style="display: none;">
    <option value="0">  --- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
    <?php foreach ($item['subcategories'] as $item2) { ?>
    <option value="<?=$item2['id']?>"
        <?php if ($item2['id'] == $this->subcategory_id) { ?> selected="selected" <?php ?>
        ><?=$item2['title']?></option>
    <?php }?>
</select>
<?php }?>
    </td>
  </tr>
  <tr>
    <th><?=$this->translate("Question:")?></th>
    <td><textarea name="question" style="width:483px;align:center;" rows="7"><?=$this->question?></textarea></td>
  </tr>
  <tr>
    <th><?=$this->translate("Name:")?></th>
    <td><input class="input-text" type=text name="name" size=45 value="<?=$this->name?>"></td>
  </tr>
  <tr>
    <th><?=$this->translate("Email:")?></th>
    <td><input class="input-text" type=text size=45 name="email" value="<?=$this->email?>"></td>
  </tr>
  <tr>
    <th><?=$this->translate("Spam control:")?></th>
    <td>
<?=$this->translate("In order to prevent spam, please copy the text shown in the image in the box below:")?>

<table>
<tr><td><img id="security_code_image" src="<?=$this->captcha?>" style="border: 1px solid #8888ff;"/></td></tr>
<tr>
    <td><input id="seccode" type="text" name="seccode" maxlength="6" style="letter-spacing: 5px;"></td>
</tr>
</table>
    </td>
  </tr>
  <tr>
    <th></th>
    <td><input type=submit value="<?=$this->translate("Send question")?>" style="font-weight: bold;"></td>
  </tr>
  <tr>
    <th></th>
    <td></td>
  </tr>
</table>


<script type="text/javascript">
category_id_previous = $("#category_id").val();
$("#subcategory_id_" + $("#category_id").val()).show();
$("#category_id").change(function() {
    $("#subcategory_id_" + category_id_previous).hide();
    $("#subcategory_id_" + $("#category_id").val()).show();
    category_id_previous = $("#category_id").val();
});
</script>


</form>
un saludo, ya me diras..... tu opinion :P