Basic: submit an external php page and return somewhere else in the current page

120 views
Skip to first unread message

Fibo

unread,
Mar 9, 2012, 5:26:15 AM3/9/12
to iphone...@googlegroups.com
I have some troubles understanding how to use iui.ajax or iui.showPageByHref, at least from page http://www.iui-js.org/documentation/0.50/iui-documentation.html
 
My problem:
- I am dynamically generating forms thru PHP, depending on values in some data array
- there is a main form which leads to child-forms.
- each child-form has its own set of <input fields, dynamically generated by PHP
- I want to pass child-input data to some common place. I am trying to do that thru a very simple php script, something like
post_session.php
<?php
session_start();
foreach ($_POST as $index=>$value) $_SESSION[$index]=$value;
?>
 (this is the simplified version, I have placed additional sanity / security checks)
- my problem: I don't find / understand how I can submit this php then go to the previous window in the initial page.
I have for example tried to define
<form id='myform' title='The title' name='myform' action="javascript:iui.ajax('post_session.php','','POST');iui.goBack();" method='POST' >
and some other variants, but did not find the right way to do things.
 
Any suggestions to the changes needed in post_sesion (eg generating some code) or in the main html code?
 
 

Sean Gilligan

unread,
Mar 14, 2012, 5:26:32 AM3/14/12
to iphone...@googlegroups.com
On 3/9/12 2:26 AM, Fibo wrote:
> I have some troubles understanding how to use *iui.ajax* or
> *iui.showPageByHref, *at least from page
> http://www.iui-js.org/documentation/0.50/iui-documentation.html


Sorry nobody has helped you yet. Have you solved your problem? Let me
know where you're at and I'll try to help you.

-- Sean

Fibo

unread,
Mar 14, 2012, 9:37:43 AM3/14/12
to iphone...@googlegroups.com
Will appreciate your help!
B-) The issue is probably a very trivial one, but I could not find an example for such a php-centric person as I am.
 
-- Bernard

Fibo

unread,
Mar 23, 2012, 10:32:33 AM3/23/12
to iphone...@googlegroups.com
Hi Sean,
 
Still no help.
 
What I am trying to do:
- in my page, main "screen" A goes to form B. This one is defined with action: php page C, method post
- I am submittig the form wit a href submit
- C.php does correctly its data-handling part, and its html code is pasted fine at the end of my page
- in fact I want this to go autoimatically to main screen A... and I am not sure how I should handle that
 
Something I have done but which does not work: have an html code generated by C.php with something like
<div id="<?php echo date("Hms"); /* handles multiple calls*/ ?>" >
  <script type="application/x-javascrript">
      // library iui/jit-loader is loaded in main page
      iui.showPageById('pageA'); // no # here
   </script>
</div>
 
Since it is enclosed with <div>s, the code is present in the result page... but I just get the toolbar and a lower level blank page (oolbar button points to screen B
 
Obviously I'm doing something wrong, but I have made several attempts without finding the right way, help welcome!
 
 
 
 

Le mercredi 14 mars 2012 10:26:32 UTC+1, Sean Gilligan a écrit :

Remi Grumeau

unread,
Mar 23, 2012, 2:58:07 PM3/23/12
to iphone...@googlegroups.com
Hi Fibo!

Please check http://we-are-gurus.com/labs/iui/sandbox/php-form/ and tell me if it's what you're trying to do (more or less)
index.php has a list + a form.
form.php deals with datas and renders an iUI screen based on what you have submitted.
(leave blank to see error panel)

This is what i have in index.php

<form id="form" title="My form" method="POST" action="form.php" name="myform" class="panel">

<h2>My form</h2>

<fieldset>

<div class="row">
<label id="text">First name</label>
<input type="text" name="firstname" placeholder="Your firstname">
</div>

<div class="row">
<label id="text">Last name</label>
<input type="text" name="lastname" placeholder="Your lastname">
</div>

<div class="row">
<label>Select a fruit</label>
<select name="fruit" size="1">
<option value="value1">Apple</option>
<option value="value2">Banana</option>
<option value="value3">Pineapple</option>
<option value="value3">Strawberry</option>
</select>
</div>

<div class="row">
<label>Number of fruits</label>
<select name="fruit_num" size="1">
<?php for($i=1;$i<10;$i++) { ?>
<option value="<?php echo $i ?>"><?php echo $i ?></option>
<?php } ?>
</select>
</div>

</fieldset>

<a href="#" type="submit" class="whiteButton">Submit form</a>

</form>


And this is what form.php looks like:

<?php
$num = intval($_POST['fruit_num']);
?><div id="result" title="Result" class="panel">
<h2>Form result</h2>
<fieldset>
<?php
if(!empty($_POST['firstname']) && !empty($_POST['lastname']))
{ ?>
<div class="row" style="text-align: left">
<p>
Welcome <?php echo $_POST['firstname'].' '.$_POST['lastname'] ?>!
</p>
</div>
<div class="row" style="text-align: left">
<p>
You asked for <?php 
if($num<=1)
echo $num.' '.$_POST['fruit'];
else
echo $num.' '.$_POST['fruit'].'s';
?>
</p>
</div>
<?php } else { ?>
<div class="row" style="text-align: left">
<p>
Please enter your firstname & lastname
</p>
</div>
<?php } ?>
</fieldset>

<a href="javascript:history.go(-1)" class="grayButton">Go back</a>

</div>


Hope this is gonna help you in any way, and keep us posted if you're good now (or not)


Remi


--
You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/iphonewebdev/-/2qkdxd-jDCgJ.

To post to this group, send email to iphone...@googlegroups.com.
To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.

Fibo

unread,
Mar 25, 2012, 11:17:23 AM3/25/12
to iphone...@googlegroups.com

Hi Remi,

Thx for your answer.
There is one main difference with what I want to achieve. How would you change your form.php so that if all is Ok, it directly returns to #index without needing any click?


Small question: is the href really needed in <a href="#" type="submit" class="whiteButton">Submit form</a> ?
To unsubscribe from this group, send email to iphonewebdev+unsubscribe@​googlegroups.com.

Remi Grumeau

unread,
Mar 26, 2012, 3:16:34 AM3/26/12
to iphone...@googlegroups.com
Le 25 mars 2012 à 17:17, Fibo a écrit :


Hi Remi,

Thx for your answer.
There is one main difference with what I want to achieve. How would you change your form.php so that if all is Ok, it directly returns to #index without needing any click?

Well, that wouldn't be a feature iUI provides out-of-the-box so i don't think so.
As a quick/crappy solution, i would ask PHP to output

<script>iui.showPageById('index')</script>

if your first screen ID value is "index".
That shows a sliding back animation to "index" since it's part of the history array, but doesn't goes back in browser history array. So if user press the browser back button, he/she will be back to the form screen.

To avoid that, i use to do a " history.go(-(history.length-1)) ".
But that would mean you are sure your user will always open your project in a new window or from a direct URL.
Otherwise, if he/she comes from Google, search / your homescreen / page B / form, this would lead him/her back to Google. 

Sadly, no easy "two lines of code" magical trick here : (
I guess a parameter to iui.goBack() function to archive that wouldn't be a bad idea...

Small question: is the href really needed in <a href="#" type="submit" class="whiteButton">Submit form</a> ?

Nope, you can even use javascript:; to be sure nothing gonna.

To view this discussion on the web visit https://groups.google.com/d/msg/iphonewebdev/-/iijRTKoJjUgJ.

To post to this group, send email to iphone...@googlegroups.com.
To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.

Fibo

unread,
Mar 27, 2012, 3:56:21 AM3/27/12
to iphone...@googlegroups.com
Does not work.
Not sure, but there are 2 options:
- I'm doing it wrong somewhere, usually the real cause. I'll give my php code below
- There is an iUI-caused problem. It seems that when javascript is executed in the external file, this is NOT in the current DOM, hence iUI does not know howto to goback in history; once this has run (with no tangible effect!), THEN the DOM is updated with the javascript text
 
My php code, called by a submit form
<?php
session_start();
foreach ($_POST as $index=>$value) { $_SESSION[$index]=$value; };
$xx=date("hms");
?><div id='<?php echo $xx; ?>'>
<script type="application/x-javascript" id='<?php echo $xx; ?>'>
iui.showPageById('etatVehicule');
</script>
</div>
 Note that if the <script> is not whithin a <div>... the js code is visible...
 
Once my code has run, the bottom of the DOM is changed to:
 
<div id="preloader"></div><div selected="true" style="left: 0%;" id="100300">
<script type="application/x-javascript"> 
iui.showPageById('etatVehicule');
</script>
</div></body></html>
(Rendering by Web Developer in Firefox, Chrome gives a cosmetically different code)
 
Another track I had considered, but where I have failed,would be that instead of simply submitting the form thru a action="xxx.php" 
(which would include the javascript backgoing) I would include the javascript backgoing code in the action itself, with something
like action="javascript:form.submit();iui.showPageById('etatVehicule');" but I probably missed something. What would you suggest?
Reply all
Reply to author
Forward
0 new messages