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 6703425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:10:11+00:00 2026-05-26T07:10:11+00:00

Here’s the situation: I have a website with a complex address form with multiple

  • 0

Here’s the situation: I have a website with a complex address form with multiple inputs for house number, street, telephone, etc. This form is used in many different places around the site.

There are several different scenarios that will affect this form:

  1. Sometimes, the form will need to be displayed ‘fresh’, with all inputs blank awaiting a new address to be added
  2. Other times, the form will need to pre-populate itself with an address pulled from the database, for editing
  3. Lastly, the form might need to re-populate itself, if a user has entered an address, submitted the form, but forgotten to add their house number – in which case it needs to return what was just entered but display a form validation warning.

However…

  • I want to only have one HTML form for addresses used across the entire site – to save repeating code
  • I want this one form to be able to handle every different scenario shown above – to save repeating code

Here’s what a sample input for the form looks like:

<div class="input">
    <input id="house_number" name="house_number" value="<?php echo set_value('house_number', $details->row('house_number'));?>"/>
    <label for="house_number">House Number</label>
</div>

As you can see, this solves scenario 2 and scenario 3 – the code echo set_value($house_number, $details->row('house_number'));?> will, by default, pre-populate itself with the data drawn from the MySQL Resultset (1), or – if it detects something has already been submitted – re-populate itself with the previous data stored in house_number.

My question is: How can I build-in Scenario 1 to this as well, ideally without repeating any code, adding nested-ifs, etc? Whenever you load the form up ‘from scratch’, PHP understandably outputs errors about $details not being set – because there is nothing to pull through from the database or my model.

My model returns a MySQL Resultset but I was thinking could you initialise this resultset with a blank row? But I wasn’t sure if that was the correct way to go about it.

Thanks!

Jack

  • 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-26T07:10:11+00:00Added an answer on May 26, 2026 at 7:10 am

    To prevent outputs errors about $details not being set, you should first check whether $details is null before using it. So you can have-

    $house_number = '';
    if($details)
    {
        $house_number = $details->row('house_number');
    } 
    

    and then

    <input id="house_number" name="house_number" value="<?php echo set_value('house_number', $house_number);?>"/>
    

    Secondly, you’ll also need to keep posted values in session so that if an error occurs and user has to return to the form, you can retain the values previously posted. Remember, these values have not been stored in database yet.

    So you can modify your code:

    $house_number = '';
    if(isset($_SESSION['house_number']))
    {
        $house_number = $_SESSION['house_number'];
    }
    else if($details)
    {
        $house_number = $details->row('house_number');
    } 
    

    I Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a problem I ran into recently. I have attributes strings of the form
Here's the situation, i want to have a user that can enter time on
Here is my situation: I am using telerik with winform. I have a dataset
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here is my code, which takes two version identifiers in the form 1, 5,
Here we go again, the old argument still arises... Would we better have a
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.

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.