Single HTML Form to Multiple PHP Scripts -


i new php programming , have question best way handle input same form can go 2 different php pages.

for example have database of projects , parameters, users can select relevant options submit form either preview script, displays of data on new page, or download option allows users download selected data in csv format.

<input type="submit" value="download" name ="download"/> <input type="submit" value="preview" name="preview"/> 

currently input sent single php script uses if statement determine best course of action

if($_post['download']){ ... }else if($_post['preview']){ ... } 

but seems messy way go handling situation. there easy way and/or best practice for

  1. creating handler php script passes relevant information more specific php file, in example split download , preview download.php , preview.php

or

  1. reuse entries form 1 php script another, example user presses preview button, looks @ data on new page, decides acceptable , download full data set pressing download button on preview page. possible make download button use same script have i.e. go , take other if branch same script generated preview?

i attempted find other related answers, hoping solution not require javascript, though open using js if best option.

you pretty have handler script, although think refer simple router, , scripts uses handlers. can modify include appropriate script depending on selected value.

if ($_post['download']) {     include 'download.php'; } else if($_post['preview']) {     include 'preview.php'; } 

as far reusing user's selected options preview download, there different ways handle that. 1 insert values hidden inputs in form in preview script action="download.php". store them in session.

in case first option simpler, because download script able use values $_post regardless of whether user went straight download or used preview first.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -