Forums

Keep data after form validation

Bouwdewijn 03 May, 2008
Hello,

First I want to say , great component, I am using Chronoforms on a few sites for some time now and no problems, untul now.

When I pu the following code in the form code,
<tr>
    <td align="right">ABC</td>
    <td><select name="select">
      <option <?php if($_POST['select']=='ABC')echo selected='selected'; >ABC
      <option <?php if($_POST['select']=='DEF')echo selected='selected'; >DEF
      <option <?php if($_POST['select']=='GHI')echo selected='selected'; >GHI
      <option <?php if($_POST['select']=='JKL')echo selected='selected'; >JKL
    </select></td>
</tr>
Whihc is an example from the how to's

This is working OK in dreamweaver, but when I put this code in the form,

I get this erroro message back:

Parse error: syntax error, unexpected '=', expecting ',' or ';' in D:\xampp\htdocs\openlucht\components\com_chronocontact\chronocontact.html.php(74) : eval()'d code on line 49

What can be wronh?

Bouwdewijn<br><br>Post edited by: GreyHead, at: 2008/05/03 19:21
Bouwdewijn 03 May, 2008
Hello everybody,

I found the answer my self, after reading my php handbook again.
The solution for a sticky select box is:

<select name="select" >
<option value="" selected>[Kies een datum]
<option <?php if($_POST['select']== 'ABC juni')echo 'selected="selected"'; ?> >ABC</option>
<option <?php if($_POST['select']== 'DEF juni')echo 'selected="selected"'; ?> >DEF</option>
<option <?php if($_POST['select']== 'GHI juni')echo 'selected="selected"'; ?> >GHI</option>
<option <?php if($_POST['select']== 'JKL juni')echo 'selected="selected"'; ?> >JKL</option>
<option <?php if($_POST['select']== 'MNO juni')echo 'selected="selected"'; ?> >MNO</option>
<option <?php if($_POST['select']== 'PQR juni')echo 'selected="selected"'; ?> >PQR</option>
</select>

The trick was 'selected="selected"'
Instead of selected='selected'

Hope this helps everybody with the same problem

Regards

Bouwdewijn
GreyHead 03 May, 2008
Hi Boudwwijn,

Looks like some characters have been dropped in the copying and pasting. An option line should look more like this
<option <?php if ( $_POST['select'] == 'ABC' ) echo "selected='selected'"; ?> >ABC</option>
Bob
Bouwdewijn 04 May, 2008
Thank you Bob, I missed the "" .
Now it is working, Until I send the form with " wrong" validation code. The form returns with all inputs correct, except the selectbox.???
I did a work arround with:
<option value="" selected>[Kies een datum]
And made it an required field. But it is nicer to have the chosen date back.

This is the code. Maybe you can look in to it and see something I overlooked. I use a javascript to validate inputs.
<p>
<label for="aanhef">Voorstelling</label><select name="voorstelling" id="reservering">
    <option value="" selected>[Kies een datum]
    <option <?php if($_POST['select']== '13 juni')echo 'selected="selected"'; ?> >13 juni</option>
    <option <?php if($_POST['select']== '14 juni')echo 'selected="selected"'; ?> >14 juni</option>
    <option <?php if($_POST['select']== '20 juni')echo 'selected="selected"'; ?> >20 juni</option>
    <option <?php if($_POST['select']== '21 juni')echo 'selected="selected"'; ?> >21 juni</option>
    <option <?php if($_POST['select']== '27 juni')echo 'selected="selected"'; ?> >27 juni</option>
    <option <?php if($_POST['select']== '28 juni')echo 'selected="selected"'; ?> >28 juni</option>

  </select>
Thanks ,

Bouwdewijn

Edited to delete most of form code.<br><br>Post edited by: GreyHead, at: 2008/05/04 13:22
GreyHead 04 May, 2008
Hi Bouwdewijn,

Your select field has the name 'voorstelling' so the $_POST entry to check is $_POST['voorstelling']

Bob

PS There's an </option> missing after [Kies een datum] too.
Bouwdewijn 04 May, 2008
Thanks Bob,

I overlooked it, After a while in the late evening and a few beers I am getting blind after reading the code over and over again.

Again thanks for your help
and have a nice weekend (for what is left from it)

Bouwdewijn
This topic is locked and no more replies can be posted.