Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:17:13+00:00 2026-05-30T06:17:13+00:00

When you have many inputs (select/textarea/input), it will look real messy when you include

  • 0

When you have many inputs (select/textarea/input), it will look real messy when you include isset()

For example:

<input id="firstname" type="text" name="firstname" 
  value="<?php echo (isset($_POST['firstname']) ? $_POST['firstname'] : "";?>">

In there alternative way so it will look tidy and maintainable?

I am using MVC Framework if that help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:17:14+00:00Added an answer on May 30, 2026 at 6:17 am

    You could build your own function that would fill values:

    function get_post( $key, $default = ''){
        if( isset( $_POST[$key])){
           return htmlspecialchars( $_POST[$key]);
        }
        return htmlspecialchars( $default);
    }
    

    And use it as:

    <input ... value="<?php echo get_post( 'firstname', 'Your name'); ?>" />
    

    Or anyway that it’d be incorporated into your framework.

    If you need more complete keys you could do it like this:

    function get_post( ){
        $args = func_get_args();
        if( count( $args) < 2){
           // Wrong usage, throw an exception
        }
        $default = array_pop( $args);
    
        $progress = $_POST;
        while( $key = array_shift( $args)){
            if( !is_array( $progress) || !isset( $progress[$key])){
               $progress = $default;
               break;
            }
            $progress = $progress[$key];
        }
        return htmlspecialchars( $progress);
    }
    
    echo get_post( 'my', 'multiple', 'keys', 'default');
    

    Preparing variables

    You may also take advantage of php array operator+ and set all variables:

    <?php
    
    $myList = array( 'name' => 'Your name', 'another' => 'Another');
    $values = $_POST + $myList;
    

    And than just:

    <?php echo htmlspecialchars( $values['name']); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textarea with many lines of input, and a JavaScript event fires
I have a dropdown box that allows users to select how many inputs they
I have a form with many input fields. When I catch the submit form
I have a form with many inputs, all of them with the class field.
I have a SELECT where I choose how many cars the user has. After
I have <input type=text class=required value=XXX name=abc> <input type=hidden class=required value=XXX name=abcd> <input type=text
I have a function with many input parameters, and I need a function that
In my MVC 2 application, I have many views with many, many input fields.
I have many years of experience in Java including Swing, Servlet and JDBC, but
I have many items inside a list control. I want each item to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.