Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Shorten my Loop code

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Shorten my Loop code

Postby vistavision » Tue Jun 03, 2014 5:54 am

Hi all,

I have a form with a result page where all answers are send to. For one form it works perfect but I want several forms to work with the same result page. So I need an automatic loop function which automaticly push all the filled in answers to the array. Please note that I am a PHP beginner.

My form:
Code: Select all
<ul class="vraaggroep">
<li><label for="v1a1"><input type="radio" id="v1a1" name="vraag1" value="v1a1" /><span>Alleenstaand</span></label></li>
<li><label for="v1a2"><input type="radio" id="v1a2" name="vraag1" value="v1a2" /><span>Samenwonend</span></label></li>
<li><label for="v1a3"><input type="radio" id="v1a3" name="vraag1" value="v1a3" /><span>Gezin met kinderen</span></label></li>
</ul>

<ul class="vraaggroep">
<li><label for="v2a1"><input type="radio" id="v2a1" name="vraag2" value="v2a1" /><span>Voorlader</span></label></li>
<li><label for="v2a2"><input type="radio" id="v2a2" name="vraag2" value="v2a2" /><span>Bovenlader</span></label></li>
</ul>

<ul class="vraaggroep">
<li id="regelsdubbel"><label for="v3a1"><input type="radio" id="v3a1" name="vraag3" value="v3a1" /><span>Onder een (werk)blad</span></label></li>
<li id="regelsdubbel"><label for="v3a2"><input type="radio" id="v3a2" name="vraag3" value="v3a2" /><span>Geintregeerd in huidige keuken</span></label></li>
<li><label for="v3a3"><input type="radio" id="v3a3" name="vraag3" value="v3a3" /><span>Volledig vrijstaand</span></label></li>
</ul>


My Result Page

Code: Select all

if ($_POST['vraag1'] == "v1a1") {
array_push($kolommen, 'v1a1');
}

if ($_POST['vraag1'] == "v1a2") {
array_push($kolommen, 'v1a2');
}

if ($_POST['vraag1'] == "v1a3") {
array_push($kolommen, 'v1a3');
}

if ($_POST['vraag2'] == "v2a1") {
array_push($kolommen, 'v2a1');
}

if ($_POST['vraag2'] == "v2a2") {
array_push($kolommen, 'v2a2');
}

if ($_POST['vraag3'] == "v3a1") {
array_push($kolommen, 'v3a1');
}

if ($_POST['vraag3'] == "v3a2") {
array_push($kolommen, 'v3a2');
}

if ($_POST['vraag3'] == "v3a3") {
array_push($kolommen, 'v3a3');
}


The numbers of questions vary per form and also the answers per question vary. Is it possible to shorten the code and use 1 code for all forms?

Thanks for helping me out!!

Kind regards,
Mark
vistavision
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sat May 10, 2014 10:35 am

Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.