Joomla! Discussion Forums



It is currently Wed Nov 25, 2009 11:21 am (All times are UTC )

 




Post new topic Reply to topic  [ 26 posts ] 
Author Message
Posted: Wed Nov 04, 2009 9:08 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Hello helpful community members :)

I have a form thats part of a component im creating nd have run into a small problem. The form right now passes post to a second view as in a preview just fine, however the preview view has a button to edit the input data which takes you to the original form view to edit the info.

I cannot for the life of me get the fields to display the data again in the input fields... Im trying userstate variables but i must not be doing something right.

Could really use a hand here, thanks.


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 9:22 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Feb 05, 2009 12:11 am
Posts: 45
Hi

I think you should create in your preview view a form with inputs type hidden for the variables you want to transmit and the edit button is the submit button.
How do you transmit the fields? you should post part of your code.


Top
   
 
Posted: Wed Nov 04, 2009 9:35 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
basically form one is submitted to form 2 as a preview if something is wrong in form 2 push the button to go back to form1(submit).

This is a snippet of the submit view
Code:
<div id="form_container">
    <form class="appnitro form-validate" method="post" action="" name="adminForm" onSubmit="return myValidate(this);">
        <div class="form_description">
            <p>Use the form below to proof/edit the information that should appear in the ad.</p>
         <p align="right"><?php echo $this->hello ?></p>
        </div>
        <ul>
           <p style="font-size:14px; font-weight:bold;">Step 1</p>
            <li class="section_break"><h3>General Information</h3></li>
         <!--<li id="li_30">
                <label class="description" for="element_30">Consortium Member:</label>
                <div><input type="checkbox" name="consortium" id="consortium" value="yes"<?php echo(($this->post->consortium="yes") ? "checked" : "") ?>></div>
            </li>-->
            <li id="li_17">
                <label class="description" for="element_17">Ad Type:</label>
                <div>
                    <select class="element select medium required" id="element_17" name="adtype">
                        <option value="<?php echo $this->getState('adtype') ?>" selected="selected"><?php echo $this->adtype ?></option>
                        <option value="adm">Administrative Ad</option>
                        <option value="fac">Faculty Ad</option>
                    </select>
                </div>
            </li>
            <li id="li_20">
                <label class="description" for="element_20">Job Category:</label>
                <div>
                    <select class="element select medium required" id="element_20" name="searchposition">
                        <option value="<?php echo $this->post['searchposition'] ?>" selected="selected"><?php echo $this->post['searchposition'] ?></option>
                        <?php echo $this->get('JobCats'); ?>
                    </select>
                </div>
            </li>
            <li id="li_1">
                <label class="description" for="element_1">Contact Email:</label>
                <div>
                    <input id="element_1" name="contact" class="element text medium required validate-email" type="text" maxlength="255" value="<?php echo $this->post['contact'] ?>"/>
                </div>
            </li>
            <li class="section_break"><h3>Ad Information</h3></li>
            <li id="li_3">
                <label class="description" for="position">Position Available:</label>
                <div>
                    <input id="position" name="position" class="element text medium required" type="text" maxlength="255" value="<?php echo $this->post['position']?>"/>
                </div>
            </li>
            <li id="li_4">
                <label class="description" for="element_4">Date Available:</label>
            <span class="required"><?php echo JHTML::_('calendar', $this->post['startdate'], "startdate", "startdate", "%m-%d-%Y"); ?></span>
         </li>
            <li id="li_6">
                <label class="description" for="school">School Name:</label>
                <div>
                    <input id="schoolname" name="school" class="element text medium required" type="text" maxlength="255" value="<?php echo $this->post['school']?>"/>
                </div>
            </li>

As you can see i have tried to echo out the the $post = JRequest::get('post'); value by reference but no luck. the preview view works fine in it displays the posted data just wont send it back if it needs editing


Top
  E-mail  
 
Posted: Wed Nov 04, 2009 10:14 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Thu Feb 05, 2009 12:11 am
Posts: 45
So this is the first form.
But can you post the preview page?


Top
   
 
Posted: Wed Nov 04, 2009 11:40 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
did you assign the reference in the view for that form?
There are variations on how this can be done so without knowing the view code it's had to generalize.
You may have to initialize that $post[] array, etc in the form.
If the view is correct it may work if you add a this pointer, but i like to re-assign it to a local variable so that there isn't a million $this-> all over the place.
Code:
$this->post["your-variable'] //get the current object


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 12:14 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
*Edit I shold have added that the preview is not a form, just html that echos the input values*Everything ive read says that to get data back from a form in the way i need it to be done, i have to use the userstate object, but now im not sure..

The view code is a mess right now because imm trying so many different things to get it sorted out but here it goes:
Code:
?php
// no direct access

defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class CareerCornerViewSubmit extends JView {
    function display($tpl = null) {
        JHTML::_('behavior.formvalidation');
       
        /*generate random customer ad id
         * should probably be the return value from paypal
         * and have it update the field via the cart
         */
        //global $mainframe,$option;
        $post = JRequest::get('post');
      
        $mainframe = &JFactory::getApplication();
        $school = $mainframe->getUserStateFromRequest("$option.school", 'school', '');
        $address1 = $mainframe->getUserStateFromRequest("$option.address1", 'address1', '');
      $city1 = $mainframe->getUserStateFromRequest("$option.city1", 'city1', '');
      $state1 = $mainframe->getUserStateFromRequest("$option.state1", 'state1', '');
      $zip1 = $mainframe->getUserStateFromRequest("$option.zip1", 'zip1', '');
      $country = $mainframe->getUserStateFromRequest("$option.country", 'country', '');
      $phone = $mainframe->getUserStateFromRequest("$option.phone", 'phone', '');
      $fax = $mainframe->getUserStateFromRequest("$option.fax", 'fax', '');
      $email = $mainframe->getUserStateFromRequest("$option.email", 'email', '');
      $web = $mainframe->getUserStateFromRequest("$option.web", 'web', '');
      $position = $mainframe->getUserStateFromRequest("$option.position", 'position', '');
      $name = $mainframe->getUserStateFromRequest("$option.name", 'name', '');
      $deadline = $mainframe->getUserStateFromRequest("$option.deadline", 'deadline', '');
      $eoe = $mainframe->getUserStateFromRequest("$option.eoe", 'eoe', '');
      $body = $mainframe->getUserStateFromRequest("$option.body", 'body', '');
      $published = $mainframe->getUserStateFromRequest("$option.published", 'published', '');
      $searchposition = $mainframe->getUserStateFromRequest("$option.searchposition", 'searchposition', '');
      $startdate = $mainframe->getUserStateFromRequest("$option.startdate", 'startdate', '');
      $reminddate = $mainframe->getUserStateFromRequest("$option.reminddate", 'reminddate', '');
      $custid = $mainframe->getUserStateFromRequest("$option.custid", 'custid', '');
      $adid = $mainframe->getUserStateFromRequest("$option.adid", 'adid', '');
      $ative = $mainframe->getUserStateFromRequest("$option.active", 'active', '');
      $adtype = $mainframe->getUserStateFromRequest("$option.adtype", 'adtype', '');
      $contact = $mainframe->getUserStateFromRequest("$option.contact", 'contact', '');
      $city2 = $mainframe->getUserStateFromRequest("$option.city2", 'city2', '');
      $state2 = $mainframe->getUserStateFromRequest("$option.state2", 'state2', '');
      $country2 = $mainframe->getUserStateFromRequest("$option.country2", 'country2', '');
      $firm = $mainframe->getUserStateFromRequest("$option.firm", 'firm', '');
      $alpha = $mainframe->getUserStateFromRequest("$option.alpha", 'alpha', '');
      $consortium = $mainframe->getUserStateFromRequest("$option.consortium", 'consortium', '');
      $busoff = $mainframe->getUserStateFromRequest("$option.busoff", 'busoff', '');
      $adcost = $mainframe->getUserStateFromRequest("$option.adcost", 'adcost', '');
      $address2 = $mainframe->getUserStateFromRequest("$option.address2", 'address2', '');
      $firmaddress1 = $mainframe->getUserStateFromRequest("$option.firmaddress1", 'firmaddress1', '');
      $firmaddress2 = $mainframe->getUserStateFromRequest("$option.firmaddress2", 'firmaddress2', '');
      $firmcity = $mainframe->getUserStateFromRequest("$option.firmcity", 'firmcity', '');
      $firmcountry = $mainframe->getUserStateFromRequest("$option.firimcountry", 'firmcountry', '');
      $firmemail = $mainframe->getUserStateFromRequest("$option.firmemail", 'firmemail', '');
      $firmfax1 = $mainframe->getUserStateFromRequest("$option.firmfax1", 'firmfax1', '');
      $firmfax2 = $mainframe->getUserStateFromRequest("$option.firmfax2", 'firmfax2', '');
      $firmfax3 = $mainframe->getUserStateFromRequest("$option.firmfax3", 'firmfax3', '');
      $firmphone1 = $mainframe->getUserStateFromRequest("$option.firmphone1", 'firmphone1', '');
      $firmphone2 = $mainframe->getUserStateFromRequest("$option.firmphone2", 'firmphone2', '');
      $firmphone3 = $mainframe->getUserStateFromRequest("$option.firmphone3", 'firmphone3', '');
      $firmstate = $mainframe->getUserStateFromRequest("$option.firmstate", 'firmstate', '');
      $firmmzip = $mainframe->getUserStateFromRequest("$option.firmmzip", 'firmmzip', '');

      $user = &JFactory::getUser();
        $usergroup = $user->get('usertype');
        if ($user->get('gid') == 107 || $user->get('gid') == 109 || $user->get('gid') == 25) {
            $hello = "Membership status: ".$user->get('usertype');
        }
        if ($usergroup == "consortium") {
            $cmember = "yes";
            $adcost = "99";
        } else {
            $cmember = "no";
            $adcost = "110";
        }
        $params = array('smilies'=>'0', 'colors'=>'0', 'fonts'=>'0', 'table'=>'0', 'media'=>'0', 'directionality'=>'0', 'insertdate'=>'0', 'inserttime'=>'0', 'fullscreen'=>'0', 'layer'=>'0', 'hr'=>'0', 'template'=>'0', 'advlink'=>'0', 'contextmenu'=>'0', 'inlinepopups'=>'0');
        $model = &$this->getModel();
        $document = &JFactory::getDocument();
        $document->addStyleSheet($this->baseurl.'/components/com_careercorner/css/view.css');
        $document->addScript($this->baseurl.'/components/com_careercorner/js/view.js');
        $editor = &JFactory::getEditor();
        $this->assignRef('post', $post);
        $this->assignRef('get', $get);
        $this->assignRef('editor', $editor);
        $this->assignRef('val', $val);
        $this->assignRef('cmember', $cmember);
        $this->assignRef('adcost', $adcost);
        $this->assignRef('greeting', $greeting);
        $this->assignRef('hello', $hello);
        $this->assignRef('params', $params);
      $this->assignRef('school', $school);
        $this->assignRef('address1',$address1);
      $this->assignRef('city1',$city1);
      $this->assignRef('state1',$state1);
      $this->assignRef('zip1',$zip);
      $this->assignRef('country',$country);
      $this->assignRef('phone',$phone);
      $this->assignRef('fax',$fax);
      $this->assignRef('email',$email);
      $this->assignRef('web',$web);
      $this->assignRef('position',$position);
      $this->assignRef('name',$name);
      $this->assignRef('deadline',$deadline);
      $this->assignRef('eoe',$eoe);
      $this->assignRef('body',$body);
      $this->assignRef('published',$published);
      $this->assignRef('searchposition',$searchposition);
      $this->assignRef('startdate',$startdate);
      $this->assignRef('reminddate',$reminddate);
      $this->assignRef('custid',$custid);
      $this->assignRef('adid',$adid);
      $this->assignRef('ative',$active);
      $this->assignRef('adtype',$adtype);
      $this->assignRef('contact',$contact);
      $this->assignRef('city2',$city2);
      $this->assignRef('state2',$state2);
      $this->assignRef('country2',$country2);
      $this->assignRef('firm',$firm);
      $this->assignRef('alpha',$alpha);
      $this->assignRef('consortium',$consortium);
      $this->assignRef('busoff',$busoff);
      $this->assignRef('adcost',$adcost);
      $this->assignRef('address2',$address2);
      $this->assignRef('firmaddress1',$firmaddress1);
      $this->assignRef('firmaddress2',$firmaddress2);
      $this->assignRef('firmcity',$firmcity);
      $this->assignRef('firmcountry',$firmcountry);
      $this->assignRef('firmemail',$firmemail);
      $this->assignRef('firmfax1',$firmfax1);
      $this->assignRef('firmfax2',$firmfax2);
      $this->assignRef('firmfax3',$firmfax3);
      $this->assignRef('firmphone1',$firmphone1);
      $this->assignRef('firmphone2',$firmphone2);
      $this->assignRef('firmphone3',$firmphone3);
      $this->assignRef('firmstate',$firmstate);
      $this->assignRef('firmmzip', $firmmzip);
        parent::display($tpl);
    }
}


See its a mess..

originally i did do the echo $this->post['variable-name'] and that seemed to work as long as the input fields existed on both pages but because the preview page is only echoing the data, there is no need for the input fields, so the variables aregetting lost


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 2:22 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
Yeah, that did sort of make my head hurt a bit...
I didn't look at it real close, but maybe you can use loops instead of all of those repetitive lines?

You have two forms. Do they both have their own views?
That may be where the variables are getting lost, by not using the view with the data.
The form will get get it's data from it's respective view unless directed otherwise.
Set the desired view and template in the controller.
Another way is put all of the methods for variable recovery in the model and call them from different views.
I believe that the data will remain until another post action takes place to overwrite the current $_POST array.
You can test that by putting this code in the form where you are 'losing" the variables.

Code:
<?php
var_dump($_POST);
?>

which should splatter the current array contents on the page.


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 2:36 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
I only have one form thats part of view->submit. This one form posts to a view->preview which only echos out the values. If anything is entered wrong i have a button on the bottom with task=submit which takes you back to the submit form. From here i need to get all the post values back in the input fields so the user can edit what was wrong.

I think the values are getting lost at the preview point part because its not a form and when i see in firebug the post data back, all thats there is the the com name, task and something else, but none of my post data.


Top
  E-mail  
 
Posted: Thu Nov 05, 2009 2:51 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
I only have one form thats part of view->submit. This one form posts to a view->preview which only echos out the values. If anything is entered wrong i have a button on the bottom with task=submit which takes you back to the submit form. From here i need to get all the post values back in the input fields so the user can edit what was wrong.

I think the values are getting lost at the preview point part because its not a form and when i see in firebug the post data back, all thats there is the the com name, task and something else, but none of my post data.


You reset the array by having two post actions. If you just want a display don't use a post action. return with a task.
I did a similar idea by using only one form for input and correction.
The echo variables are null ($_POST is null) on the first pass. When the form is submitted with an error, such as a blank required field, the controller returns to same the form which now has populated fields and the error message.
I like to keep it simple.


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 1:39 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Sorry for being so late getting back on this. How would i accomplish this then? I need to get these values back into the fields if something needs editing and forward to step 3 for insertion into the database and ordering?

Thanks so much for the help thus far


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 2:34 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
Sorry for being so late getting back on this. How would i accomplish this then? I need to get these values back into the fields if something needs editing and forward to step 3 for insertion into the database and ordering?

Thanks so much for the help thus far


Your approach is different than mine, so it's hard say what to do exactly since I am not writing the code myself.
Your idea is to have a separate "review' or "display only" as I understand it.There is only one $_POST array underlying the session. If you use method = post on the display form, it will reset the array with the data from the display form which was the hidden component option data, I guess...
Did you put that var_dump code at the top of the "review form"?
Code:
<?php
var_dump($this->your_array); //your_array is what was assigned in the view. See if it's still there...
?>

Instead ,use JRoute on a button to redirect back to the controller WITHOUT posting , so that the original data is maintained. The controller then picks up the task set in the "display form' and redirects back to the original form that can it can be edited or if all was declared OK by the user, the controller stores the data and sends a success message.
In fact, the "review form" need not be be a form at all. Just display the data and provide "edit and "continue" buttons with the appropriate task and option settings.

This is just an outline, not a concrete code solution, but I hope it will give you some new ideas on how to complete your project.


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 4:42 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
yes there is one originating post session but i need to carry those vars across back and forth between the preview and submit pages and then eventually to an order form.

I did print_r the on the preview page and everything is there from the submitted form. How would i use JRoute on a button, cant seem to find it in the api..


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 8:41 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
yes there is one originating post session but i need to carry those vars across back and forth between the preview and submit pages and then eventually to an order form.

I did print_r the on the preview page and everything is there from the submitted form. How would i use JRoute on a button, cant seem to find it in the api..


try:

http://api.joomla.org/Joomla-Framework/JRoute.html

http://docs.joomla.org/Routing

http://docs.joomla.org/JRoute


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 10:02 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Looked at those, thank you but im being dense or just having a really long couple of work days. Im not sure how to make that into a clickable button thats not in a form. ive see the <button> attributes and then input in various components but they dont seem to be used for what im looking for, would you have a example of how this button should be rendered?


Top
  E-mail  
 
Posted: Fri Nov 06, 2009 11:26 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
Looked at those, thank you but im being dense or just having a really long couple of work days. Im not sure how to make that into a clickable button thats not in a form. ive see the <button> attributes and then input in various components but they dont seem to be used for what im looking for, would you have a example of how this button should be rendered?


Like a hyper link :
use the JRoute within the button method

http://api.joomla.org/__filesource/fsou ... p.html#a35


Top
  E-mail  
 
Posted: Mon Nov 09, 2009 5:21 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Thank you again for that. The link seems broken but i just added a js back button and that worked for getting back to the form with values inserted however because the preview page(step2) is not a form, the order button which takes you to order or step3 wont work...

I dont think the api docs are written well enough or im just not grasping the idea of making a clickable JHTML button. You may shoot me now.


Top
  E-mail  
 
Posted: Mon Nov 09, 2009 11:57 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Ok so i put step 2 back into a form and i lose all post vars with the js back button as expected. I think i want to use http://api.joomla.org/Joomla-Framework/ ... etchButton but i really cant figure out the docs.

Why is it so difficult to pass these values simply between 2 different views?


Top
  E-mail  
 
Posted: Tue Nov 10, 2009 1:07 am 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
Ok so i put step 2 back into a form and i lose all post vars with the js back button as expected. I think i want to use http://api.joomla.org/Joomla-Framework/ ... etchButton but i really cant figure out the docs.

Why is it so difficult to pass these values simply between 2 different views?


Technically you can't pass vars among views.
What you can do is call the the same method from the same model from different views.
If all the method does it do getVar() and ref assignments,I don't think a "display only" page will reset the POST vars.


Top
  E-mail  
 
Posted: Tue Nov 10, 2009 1:45 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
becyn wrote:
just_chris wrote:
Ok so i put step 2 back into a form and i lose all post vars with the js back button as expected. I think i want to use http://api.joomla.org/Joomla-Framework/ ... etchButton but i really cant figure out the docs.

Why is it so difficult to pass these values simply between 2 different views?


Technically you can't pass vars among views.
What you can do is call the the same method from the same model from different views.
If all the method does it do getVar() and ref assignments,I don't think a "display only" page will reset the POST vars.


Thats exactly whats happening. My button code from the display page looks like this:
Code:
<input class="button" type="submit" name="task" value="edit" onclick="history.go(-1)" />
            <input class="button" type="submit" name="task" value="order" />
            <input type="hidden" name="option" value="<?php echo $option; ?>" />
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="consortium" value="<?php echo $this->cmember; ?>" />
            <input type="hidden" name="adcost" value="<?php echo $this->adcost; ?>" />
            <input type="hidden" name="boxchecked" value="0" />
            <input type="hidden" name="controller" value="" />
                <?php echo JHTML::_('form.token'); ?>

This is not a form now and when I click on the back button the fields are mnow blank and the the order button doesnt work at all :(


Top
  E-mail  
 
Posted: Tue Nov 10, 2009 3:46 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
becyn wrote:
just_chris wrote:
Ok so i put step 2 back into a form and i lose all post vars with the js back button as expected. I think i want to use http://api.joomla.org/Joomla-Framework/ ... etchButton but i really cant figure out the docs.

Why is it so difficult to pass these values simply between 2 different views?


Technically you can't pass vars among views.
What you can do is call the the same method from the same model from different views.
If all the method does it do getVar() and ref assignments,I don't think a "display only" page will reset the POST vars.


Thats exactly whats happening. My button code from the display page looks like this:
Code:
<input class="button" type="submit" name="task" value="edit" onclick="history.go(-1)" />
            <input class="button" type="submit" name="task" value="order" />
            <input type="hidden" name="option" value="<?php echo $option; ?>" />
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="consortium" value="<?php echo $this->cmember; ?>" />
            <input type="hidden" name="adcost" value="<?php echo $this->adcost; ?>" />
            <input type="hidden" name="boxchecked" value="0" />
            <input type="hidden" name="controller" value="" />
                <?php echo JHTML::_('form.token'); ?>

This is not a form now and when I click on the back button the fields are mnow blank and the the order button doesnt work at all :(


You have effectively turned that page into a form by using type=submit in the button!
Consult W3 or similar site for the functional types . You may want "button" .
You are using hidden fields. How do you think they are read other than the underlying $_post array, which you said that you don't wish to reset with new data? Subit sends the name-value pairs! If they are now blank, all you have left is what you sent in the hidden inputs!
All you need is something like an internal hyperlink to pass back to your component with a task.
If you are not sure what that looks like, turn off SEF and look at the URLs produced by working components.
DO NOT USE SUBMIT. YOU WILL LOSE THE PREVIOUS DATA.


Top
  E-mail  
 
Posted: Tue Nov 10, 2009 11:21 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Okay i have moved both the submit and the preview tmpls into the same view. I guess what i need to understand is how to create the js that will allow me to accomplish the task of posting and editing input values. funnily enough, i had no problem building out the admin backend for this piece, which i guess is what confuses me more about the frontend.

Thank you again for all of your help in this matter.


Top
  E-mail  
 
Posted: Thu Nov 12, 2009 4:30 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Ok so right now i have 2views, one view for submit which is a form and one view for preview which is a form. in my modal i simply have
Code:
    function getPost() {
       $post=JRequest::get('post');
        foreach ($post as $k=>$v) {
            echo "<input type='hidden' name='$k' value='$v' />";
        }
    }


and in my view i have:
Code:
$model = &$this->getModel();
$post = $model->getPost();
//$post = JRequest::get('post');   
$this->assignRef('post', $post);


and my controller is like this:
Code:
function display() {
       
      $model = $this->getModel('submit');
        switch ($this->getTask()) {   
            case 'preview': {
                   JRequest::setVar('layout', 'default');
                    JRequest::setVar('view', 'prev');
                }
                break;
            case 'edit': {
                    JRequest::setVar('layout', 'default');
                    JRequest::setVar('view', 'submit');
                }
                break;
            case 'order': {
                    //$this->save();
                    JRequest::setVar('layout', 'order');
                    JRequest::setVar('view', 'submit');
                }
                break;
        }
       
        parent::display();
    }

Im getting an error though now that reads:
Quote:
Fatal error: Cannot use object of type stdClass as array in /views/submit/tmpl/default.php on line 48

Line 48 refers to where i start to echo out my post vars like echo $this->post['post-var'].

What am i doing wrong??


Top
  E-mail  
 
Posted: Thu Nov 12, 2009 9:19 pm 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
I don't know exactly, but you say you are using two views. In Joomla the JView method look for a model of the same name, so if you are using one model with both, you need to specify the model.
Try using the JView method like I have below
Code:

$data = &get('post', 'model-name');//this JView-NOT JRequest !!
$this->assignRef('data', $data);


I changed the array name because you maty be using post in too many places casing some kind of ambiguity. (At least on my part..). I'm also uncomfortable because it is too close to the PHP $_POST
global.
Code:
//in default.php
$this->data['var']


The model needs a reworking here:
Code:
function getPost() {
       $post=JRequest::get('post'); //$post will be a key=>value array as is. See API !!
        return $this->$post
        }
    }



Top
  E-mail  
 
Posted: Fri Nov 13, 2009 12:32 am 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Im so confused, I have my model like this:
Code:
    function getPost() {
        $post = JRequest::get('post'); //$post will be a key=>value array as is. See API !!
        return $this->$post;
    }


My view like this:
Code:
        $data = JView::get('post', 'submit');
        $this->assignRef('data', $data);


and in my templates im echoing $this->data['var']. The submit view posts to the preview view.

my preview im calling the same model, submit so my preview view has $data = JView::get('post', 'submit');

Now when i submit my form to the preview, it only echos out S's, which im pretty sure is the s in the views second argument. and also the edit link goes back to the submit form, but nothing gets shown....

ARrrrggg


Top
  E-mail  
 
Posted: Fri Nov 13, 2009 2:10 am 
Joomla! Explorer
Joomla! Explorer
Offline

Joined: Mon Aug 11, 2008 1:16 am
Posts: 312
just_chris wrote:
Im so confused, I have my model like this:
Code:
    function getPost() {
        $post = JRequest::get('post'); //$post will be a key=>value array as is. See API !!
        return $this->$post;
    }


My view like this:
Code:
        $data = JView::get('post', 'submit');
        $this->assignRef('data', $data);


and in my templates im echoing $this->data['var']. The submit view posts to the preview view.

my preview im calling the same model, submit so my preview view has $data = JView::get('post', 'submit');

Now when i submit my form to the preview, it only echos out S's, which im pretty sure is the s in the views second argument. and also the edit link goes back to the submit form, but nothing gets shown....

ARrrrggg


just_Chris,

I have no magic bullet that will end all of your issues.
You still have input fields in the preview form which you want only to display the data.
The input and hidden fields are USELESS unless you do a type=submit which will trash all the previous data, so the preview needs a total rewrite.
Also, I mentioned before that you should look at how other components do their process handling. You need to return to the controller with a task. What you are doing is non-standard, but not incorrect either, but something you are going to be pretty much "on your own" with. This method of doing things may be a bit too ambitious for you at this time.
The best thing you can do for yourself is to take some time to really understand how this stuff works.
Having some basics down ,makes the writing and troubleshooting process much easier.
Patching together some "Frankenstein" code will just make you crazy. Been there...


Top
  E-mail  
 
Posted: Mon Nov 23, 2009 6:49 pm 
Joomla! Apprentice
Joomla! Apprentice
Offline

Joined: Sat Jan 17, 2009 8:18 pm
Posts: 23
Managed to get this working using just one view and manually declaring all my hidden fields in my preview tmpl. probably not the most ideal way to do this but it works. Thanks again for all the help.


Top
  E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ] 

Quick reply

 



Who is online

Users browsing this forum: arrowjoe, darb, Fly06, kirilisa, kkaal, rfs1970, Sergey Romanov and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group